結果
問題 | No.55 正方形を描くだけの簡単なお仕事です。 |
ユーザー | 明智重蔵 |
提出日時 | 2015-08-30 21:53:40 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 4,020 bytes |
コンパイル時間 | 909 ms |
コンパイル使用メモリ | 115,608 KB |
実行使用メモリ | 27,596 KB |
最終ジャッジ日時 | 2024-11-14 13:51:04 |
合計ジャッジ時間 | 2,470 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
27,468 KB |
testcase_01 | AC | 30 ms
25,296 KB |
testcase_02 | AC | 30 ms
27,208 KB |
testcase_03 | AC | 31 ms
27,468 KB |
testcase_04 | AC | 30 ms
27,328 KB |
testcase_05 | AC | 29 ms
23,344 KB |
testcase_06 | AC | 30 ms
27,480 KB |
testcase_07 | AC | 29 ms
27,224 KB |
testcase_08 | AC | 31 ms
25,160 KB |
testcase_09 | AC | 30 ms
27,204 KB |
testcase_10 | AC | 28 ms
23,348 KB |
testcase_11 | AC | 29 ms
25,520 KB |
testcase_12 | AC | 30 ms
27,232 KB |
testcase_13 | AC | 30 ms
27,332 KB |
testcase_14 | AC | 30 ms
25,548 KB |
testcase_15 | AC | 30 ms
27,356 KB |
testcase_16 | AC | 29 ms
25,168 KB |
testcase_17 | AC | 30 ms
25,548 KB |
testcase_18 | AC | 30 ms
25,420 KB |
testcase_19 | AC | 30 ms
27,208 KB |
testcase_20 | AC | 29 ms
27,340 KB |
testcase_21 | AC | 29 ms
25,176 KB |
testcase_22 | AC | 30 ms
27,596 KB |
testcase_23 | AC | 30 ms
27,464 KB |
testcase_24 | AC | 29 ms
25,292 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("0 0 1 0 0 1"); //1 1 } else if (InputPattern == "Input2") { WillReturn.Add("0 0 2 0 2 1"); //-1 } else if (InputPattern == "Input3") { WillReturn.Add("1 2 2 -1 -1 -2"); //-2 1 } else if (InputPattern == "Input4") { WillReturn.Add("8 10 14 14 13 9"); //9 15 } 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 X1 = wkArr[0]; int Y1 = wkArr[1]; int X2 = wkArr[2]; int Y2 = wkArr[3]; int X3 = wkArr[4]; int Y3 = wkArr[5]; int X4, Y4; //場合1 線12が対角線となる場合 //4=1+ベクトル32 X4 = X1 + X2 - X3; Y4 = Y1 + Y2 - Y3; if (IsSquare(X1, Y1, X3, Y3, X2, Y2, X4, Y4)) { Console.WriteLine("{0} {1}", X4, Y4); return; } //場合2 線13が対角線となる場合 //4=1+ベクトル23 X4 = X1 + X3 - X2; Y4 = Y1 + Y3 - Y2; if (IsSquare(X1, Y1, X2, Y2, X3, Y3, X4, Y4)) { Console.WriteLine("{0} {1}", X4, Y4); return; } //場合3 線14が対角線となる場合 //4=1+ベクトル13+ベクトル12 X4 = X1 + X3 - X1 + X2 - X1; Y4 = Y1 + Y3 - Y1 + Y2 - Y1; if (IsSquare(X1, Y1, X2, Y2, X4, Y4, X3, Y3)) { Console.WriteLine("{0} {1}", X4, Y4); return; } Console.WriteLine(-1); } //傾きを返す static void DeriveKatamuki(int pX1, int pY1, int pX2, int pY2, out int pBunsi, out int pBunbo) { pBunsi = pY2 - pY1; pBunbo = pX2 - pX1; } //ABCDが正方形を作成可能かを返す static bool IsSquare(int AX, int AY, int BX, int BY, int CX, int CY, int DX, int DY) { int Kyori1 = CalcKyori(AX, AY, BX, BY); int Kyori2 = CalcKyori(BX, BY, CX, CY); int Kyori3 = CalcKyori(CX, CY, DX, DY); int Kyori4 = CalcKyori(AX, AY, DX, DY); //4つの辺の長さが等しいこと if (Kyori1 != Kyori2) return false; if (Kyori1 != Kyori3) return false; if (Kyori1 != Kyori4) return false; int Bunsi1, Bunbo1; DeriveKatamuki(AX, AY, BX, BY, out Bunsi1, out Bunbo1); int Bunsi2, Bunbo2; DeriveKatamuki(BX, BY, CX, CY, out Bunsi2, out Bunbo2); int Bunsi3, Bunbo3; DeriveKatamuki(CX, CY, DX, DY, out Bunsi3, out Bunbo3); int Bunsi4, Bunbo4; DeriveKatamuki(DX, DY, AX, AY, out Bunsi4, out Bunbo4); Func<int, int, int, int, bool> Is90Do = (pBunsi1, pBunbo1, pBunsi2, pBunbo2) => { if (pBunsi1 == 0 && pBunbo2 == 0) return true; if (pBunbo1 == 0 && pBunsi2 == 0) return true; if (pBunsi1 * pBunsi2 % (pBunbo1 * pBunbo2) != 0) return false; return (pBunsi1 * pBunsi2 / (pBunbo1 * pBunbo2) == -1); }; if (Is90Do(Bunsi1, Bunbo1, Bunsi2, Bunbo2) == false) return false; if (Is90Do(Bunsi2, Bunbo2, Bunsi3, Bunbo3) == false) return false; if (Is90Do(Bunsi3, Bunbo3, Bunsi4, Bunbo4) == false) return false; if (Is90Do(Bunsi4, Bunbo4, Bunsi1, Bunbo1) == false) return false; return true; } //ユークリッド距離の2乗を返す static int CalcKyori(int pX1, int pY1, int pX2, int pY2) { return (pX1 - pX2) * (pX1 - pX2) + (pY1 - pY2) * (pY1 - pY2); } }