0
0

AtCoderをC#で始めてみたよ -AtCoder Beginner Contest 362-

Posted at

ABC362に参加したぞーー361は諸事情でパスしました
前回のはこちら

結果

また,3完...やはりBFSとかDFSとか覚えてないと4問目からきついっす

A - Buy a Pen

image.png

コメント

C色以外の2色の最小値を選べばいいのでifで分岐してMath.Minで解決だね

using System;
using System.Linq;

class Program
{
    static int r,g,b;
    static string c;
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        (r,g,b) = (int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]));
        c = Console.ReadLine();
        List<int> rgb = new List<int> { r, g, b };
        if(c == "Red") Console.WriteLine(Math.Min(rgb[1], rgb[2]));
        else if(c == "Green") Console.WriteLine(Math.Min(rgb[0], rgb[2]));
        else if(c == "Blue") Console.WriteLine(Math.Min(rgb[0], rgb[1]));

    }
}

B - Right Triangle

image.png

コメント

直角三角形であるかどうかを調べたいなら三平方の定理しかない.
Math.Powはdouble型なのでintに変換する必要あり

using System;
using System.Linq;

class Program
{
    static int[,] point = new int[3,2];
    static void Main(string[] args)
    {
        string[] input;
        for(int i = 0; i < 3; i++){
            input = Console.ReadLine().Split(' ');
            (point[i,0], point[i,1]) = (int.Parse(input[0]), int.Parse(input[1]));
        }

        int a,b,c;
        a = (int)(Math.Pow(point[0,0] - point[1,0], 2) + Math.Pow(point[0,1] - point[1,1], 2));
        b = (int)(Math.Pow(point[1,0] - point[2,0], 2) + Math.Pow(point[1,1] - point[2,1], 2));
        c = (int)(Math.Pow(point[2,0] - point[0,0], 2) + Math.Pow(point[2,1] - point[0,1], 2));

        if(a+b==c || b+c==a || c+a==b) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

C - Sum = 0

image.png

コメント

ここ考えすぎて時間かかったけど,終わってみれば簡単な問題だったな...
一旦全部Liを採用しておいてsumが0になるまで順番にRiにしていくって作業を繰り返し行うだけでよかった

using System;
using System.Linq;

class Program
{
    static int n;
    static int[] l = new int[200010], r = new int[200010];
    static void Main(string[] args)
    {
        n = int.Parse(Console.ReadLine());
        string[] input;
        for(int i = 1; i <= n; i++){
            input = Console.ReadLine().Split(' ');
            (l[i], r[i]) = (int.Parse(input[0]), int.Parse(input[1]));
        } 

        long sum = 0;
        long[] ans = new long[200010];
        for(int i = 1; i <= n; i++)
        {
            sum += l[i];
            ans[i] = l[i];
        }

        if (sum > 0)
        {
            Console.WriteLine("No");
            return;
        }

        for(int i = 1; i <= n; i++)
        {
            if(r[i]-l[i] < -sum){
                ans[i] = r[i];
                sum += r[i]-l[i];
            }else if(r[i]-l[i] >= -sum){
                ans[i] = l[i]-sum;
                sum = 0;
                Console.WriteLine("Yes");
                break;
            }
        }

        if(sum==0) Console.WriteLine(string.Join(" ", ans.Skip(1).Take(n)));
        else Console.WriteLine("No");
    }
}

D - Shortest Path 3

image.png

コメント

単純連結無向グラフ...???なんすか単純連結無向グラフって
はい,勉強します.
内容自体はグラフの最短経路長を求める練習問題らしいのでやっといたほうがいいね,ダイクストラ法?なんすかダイクストラ法って

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0