結果
問題 | No.635 自然門松列 |
ユーザー | Risen |
提出日時 | 2018-01-19 22:37:53 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 69 ms / 650 ms |
コード長 | 5,451 bytes |
コンパイル時間 | 3,597 ms |
コンパイル使用メモリ | 111,176 KB |
実行使用メモリ | 23,836 KB |
最終ジャッジ日時 | 2023-09-05 13:08:53 |
合計ジャッジ時間 | 6,299 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
21,664 KB |
testcase_01 | AC | 65 ms
23,612 KB |
testcase_02 | AC | 67 ms
21,688 KB |
testcase_03 | AC | 66 ms
21,832 KB |
testcase_04 | AC | 68 ms
23,608 KB |
testcase_05 | AC | 68 ms
23,640 KB |
testcase_06 | AC | 67 ms
21,752 KB |
testcase_07 | AC | 68 ms
21,800 KB |
testcase_08 | AC | 67 ms
23,584 KB |
testcase_09 | AC | 65 ms
21,760 KB |
testcase_10 | AC | 68 ms
21,788 KB |
testcase_11 | AC | 68 ms
23,640 KB |
testcase_12 | AC | 68 ms
21,684 KB |
testcase_13 | AC | 68 ms
21,772 KB |
testcase_14 | AC | 69 ms
21,588 KB |
testcase_15 | AC | 66 ms
23,836 KB |
testcase_16 | AC | 67 ms
21,616 KB |
testcase_17 | AC | 67 ms
21,744 KB |
testcase_18 | AC | 68 ms
21,680 KB |
testcase_19 | AC | 68 ms
19,572 KB |
testcase_20 | AC | 68 ms
21,792 KB |
testcase_21 | AC | 67 ms
19,656 KB |
testcase_22 | AC | 68 ms
23,676 KB |
testcase_23 | AC | 68 ms
21,784 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; public struct Point { public double X; public double Y; public Point(Point p) { X = p.X; Y = p.Y; } public Point(int x, int y) { X = x; Y = y; } public Point(double x, double y) { X = x; Y = y; } public static bool operator ==(Point a, Point b) { if ((object)a == null || (object)b == null) { if ((object)a == null && (object)b == null) { return true; } return false; } return (a.X == b.X && a.Y == b.Y); } public static bool operator !=(Point a, Point b) { if ((object)a == null || (object)b == null) { if ((object)a == null && (object)b == null) { return false; } return true; } return (a.X != b.X || a.Y != b.Y); } public static Point operator *(Point a, double i) { return new Point(a.X * i, a.Y * i); } public static Point operator /(Point a, double i) { return new Point(a.X / i, a.Y / i); } //objと自分自身が等価のときはtrueを返す public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return false; } Point p = (Point)obj; return (X == p.X && Y == p.Y); } //Equalsがtrueを返すときに同じ値を返す public override int GetHashCode() { int prime = 31; int result = 1; long temp; temp = BitConverter.DoubleToInt64Bits(X); result = prime * result + (int)(temp ^ (temp >> 32)); temp = BitConverter.DoubleToInt64Bits(Y); result = prime * result + (int)(temp ^ (temp >> 32)); return result; } public Point Clone() { return new Point(X, Y); } public void Reverse() { X = -X; Y = -Y; } public static Point operator +(Point a, Point b) { return new Point(a.X + b.X, a.Y + b.Y); } public static Point operator -(Point a, Point b) { return new Point(a.X - b.X, a.Y - b.Y); } public static Point operator +(Point a) { return new Point(+a.X, +a.Y); } public static Point operator -(Point a) { return new Point(-a.X, -a.Y); } // 直線ABと直線CDの交点を求める // onlySegment:trueで線分ABと線分CDの交点を求める public static Point? GetCrossPoint(Point a, Point b, Point c, Point d, bool onlySegment = false) { double delta = (b.X - a.X) * (d.Y - c.Y) - (b.Y - a.Y) * (d.X - c.X); // 平行線 if (delta == 0) { return null; } double u = ((c.X - a.X) * (d.Y - c.Y) - (c.Y - a.Y) * (d.X - c.X)) / delta; double v = ((c.X - a.X) * (b.Y - a.Y) - (c.Y - a.Y) * (b.X - a.X)) / delta; if (onlySegment) { // 線分AB内で交わらない if (u < 0.0 || u > 1.0) { return null; } // 線分CD内で交わらない if (v < 0.0 || v > 1.0) { return null; } } Point cross; cross.X = a.X + u * (b.X - a.X); cross.Y = a.Y + u * (b.Y - a.Y); // 誤差対策 if (a.X == b.X) { cross.X = a.X; } else if (c.X == d.X) { cross.X = c.X; } if (a.Y == b.Y) { cross.Y = a.Y; } else if (c.Y == d.Y) { cross.Y = c.Y; } return cross; } } class Solution { static bool WillPineDecoration(int[] array) { var start = array.Take(3).ToArray(); var grow = array.Skip(3).ToArray(); var line = new Tuple<Point, Point>[3]; for (int i = 0; i < 3; i++) { line[i] = new Tuple<Point, Point>(new Point(0, start[i]), new Point(1, start[i] + grow[i])); } var e = 0.000001; var time = new List<double> { 0, e }; foreach (int i in new int[] { 0, 2 }) { var cross = Point.GetCrossPoint(line[i].Item1, line[i].Item2, line[1].Item1, line[1].Item2); if (cross != null && ((Point)cross).X > 0) { time.Add(((Point)cross).X - e); time.Add(((Point)cross).X + e); } } foreach (var t in time) { var len = Enumerable.Range(0, 3).Select(i => start[i] + grow[i] * t).ToArray(); if (len.Max() == len[1] || len.Min() == len[1]) { if (len[0] != len[1] && len[1] != len[2] && len[2] != len[0]) { return true; } } } return false; } static void Main() { var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (WillPineDecoration(array)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }