LoginSignup
1
1

More than 5 years have passed since last update.

POH6 C# 解答

Posted at

ネタバレのため、paizaオンラインハッカソン6問題をまだやってない人は見ないことをお勧めする。
POH6+は明日以降。

緑川つばめ

コメントするようなこともない。


public class Hello{
public static void Main(){
// 自分の得意な言語で
// Let's チャレンジ!!
var N = int.Parse(System.Console.ReadLine());
System.Console.WriteLine(N+N%10+N/10);
}
}

霧島京子

一番面倒ではあった。処理終了条件を付けられるけど、なくても最短時間っぽいのでそのままとした。
読み込んだ数列のint配列化が1行で出来るようになったのはありがたい。

using System;
using System.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            bool[] map = new bool[N];   //  到達可能マップ
            int goal = N-1;
            map[goal] = true;
            var t = Console.ReadLine().Split(' ').Select(k => int.Parse(k)).ToArray();
            for (int j = 0; j < (N - 2); j++) {
                for (int i = 1; i < goal; i++)
                {
                    var index = t[i] + i;
                    if (!map[i] && index < N && index > 0 && map[index])
                    {
                        map[i] = true;
                    }
                }
            }
            int m = int.Parse(Console.ReadLine());
            for (int i = 0; i < m; i++)
            {
                var d = int.Parse(Console.ReadLine());
                Console.WriteLine((d < N && map[d]) ? "Yes" : "No");
            }
        }
    }
}

六村リオ

誤差問題。3の時の計算を単純化出来ればよいのだろう。
コーヒー総量は整数で求められることを利用し、飲んだとき水の量だけ計算し続けるようにした。
分母が整数で誤差がなくなったのでおそらく正解だろう。
総量-水=粉 なので水か粉のどちらか分かっていれば答えは求まる。

using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            double coffee = 0, water = 0;
            int weight = 0;
            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                var r = Console.ReadLine().Split(' ');
                var t = int.Parse(r[0]);
                var s = int.Parse(r[1]);
                switch (t)
                {
                    case 1:
                        water += s;
                        weight += s;
                        break;
                    case 2:
                        weight += s;
                        break;
                    case 3:
                        water = water * (weight - s) / weight;
                        weight -= s;
                        break;
                }
            }
            coffee = weight - water;
            int ans = (int)(coffee * 100.0 / weight);
            Console.WriteLine(ans);
        }
    }
}
1
1
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
1
1