AtCoderのABC    次のABCの問題へ    前のABCの問題へ

ABC168-C : (Colon)


問題へのリンク


C#のソース

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 4 9 0");
            //5.00000000000000000000
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 4 10 40");
            //4.56425719433005567605
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int A = wkArr[0];
        int B = wkArr[1];
        int H = wkArr[2];
        int M = wkArr[3];

        //合計分数を求める
        double TotalMin = 60 * H + M;

        double HourDec = 0; //時針の角度(度数法)
        double MinuteDec = 0; //分針の角度(度数法)

        //時針は1分で0.5度進む
        //分針は1分で6度進む
        HourDec = (TotalMin * 0.5) % 360;
        MinuteDec = (TotalMin * 6) % 360;

        double ThetaDec = Math.Abs(HourDec - MinuteDec);
        ThetaDec = Math.Min(ThetaDec, 360 - ThetaDec);

        double ThetaRad = ThetaDec * Math.PI / 180;

        Console.WriteLine(Math.Sqrt(A * A + B * B - 2 * A * B * Math.Cos(ThetaRad)));
    }
}


解説

角度を求めてから余弦定理を使ってます。