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

ABC259-B Counterclockwise Rotation


問題へのリンク


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("2 2 180");
            //-2 -2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 0 120");
            //-2.49999999999999911182 4.33012701892219364908
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("0 0 11");
            //0.00000000000000000000 0.00000000000000000000
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("15 5 360");
            //15.00000000000000177636 4.99999999999999555911
        }
        else if (InputPattern == "Input5") {
            WillReturn.Add("-505 191 278");
            //118.85878514480690171240 526.66743699786547949770
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct PointDef
    {
        internal double X;
        internal double Y;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        double[] wkArr = InputList[0].Split(' ').Select(pX => double.Parse(pX)).ToArray();
        double A = wkArr[0];
        double B = wkArr[1];
        double C = wkArr[2];

        PointDef Point;
        Point.X = A;
        Point.Y = B;

        // 角度を求める
        double Rad = DeriveRad(C);

        PointDef KaitenVector = Exec1JiHenkan(Point, Math.Sin(Rad), Math.Cos(Rad));

        Console.WriteLine("{0} {1}", KaitenVector.X, KaitenVector.Y);
    }

    // 度数法の角度をラジアンに変換
    static double DeriveRad(double pDo)
    {
        return pDo * Math.PI / 180;
    }

    // ベクトルとSinとCosを引数として、回転したベクトルを返す
    static PointDef Exec1JiHenkan(PointDef pPos, double pSin, double pCos)
    {
        PointDef WillReturn;
        WillReturn.X = pCos * pPos.X + pPos.Y * -pSin;
        WillReturn.Y = pSin * pPos.X + pPos.Y * pCos;
        return WillReturn;
    }
}


解説

ベクトルの一次変換を使ってます。