結果
問題 | No.245 貫け! |
ユーザー | suigingin |
提出日時 | 2015-07-19 21:38:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 226 ms / 5,000 ms |
コード長 | 1,592 bytes |
コンパイル時間 | 4,733 ms |
コンパイル使用メモリ | 74,580 KB |
実行使用メモリ | 56,964 KB |
最終ジャッジ日時 | 2023-09-22 19:28:37 |
合計ジャッジ時間 | 7,783 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,776 KB |
testcase_01 | AC | 121 ms
55,908 KB |
testcase_02 | AC | 121 ms
55,824 KB |
testcase_03 | AC | 121 ms
54,568 KB |
testcase_04 | AC | 120 ms
55,752 KB |
testcase_05 | AC | 122 ms
55,880 KB |
testcase_06 | AC | 126 ms
56,060 KB |
testcase_07 | AC | 123 ms
55,368 KB |
testcase_08 | AC | 137 ms
55,904 KB |
testcase_09 | AC | 173 ms
56,188 KB |
testcase_10 | AC | 142 ms
55,740 KB |
testcase_11 | AC | 166 ms
54,224 KB |
testcase_12 | AC | 202 ms
56,136 KB |
testcase_13 | AC | 192 ms
56,964 KB |
testcase_14 | AC | 196 ms
56,452 KB |
testcase_15 | AC | 196 ms
56,208 KB |
testcase_16 | AC | 226 ms
56,096 KB |
testcase_17 | AC | 203 ms
56,316 KB |
testcase_18 | AC | 194 ms
56,532 KB |
testcase_19 | AC | 222 ms
56,376 KB |
ソースコード
import java.util.Scanner; public class No_245 { Scanner sc = new Scanner(System.in); int N; Point[][] p; void run() { N = sc.nextInt(); p = pointArray(N); int max = 1; for (int i = 0; i < N; i++) { Point o1 = p[i][0]; Point o2 = p[i][1]; for (int j = 0; j < N; j++) { if (i == j) continue; Point p1 = p[j][0]; Point p2 = p[j][1]; max = Math.max(max, crossCnt(o1, p1, i, j)); max = Math.max(max, crossCnt(o1, p2, i, j)); max = Math.max(max, crossCnt(o2, p1, i, j)); max = Math.max(max, crossCnt(o2, p2, i, j)); } } System.out.println(max); } int crossCnt(Point s, Point t, int non1, int non2) { int cnt = 0; for (int i = 0; i < N; i++) { if (lineCross(s, t, p[i][0], p[i][1])) cnt++; } return cnt; } // 直線p1->p2と線分p3->p4が交わるかどうか判定 // p1 != p2 でなければ破綻することに注意 boolean lineCross(Point p1, Point p2, Point p3, Point p4) { if (p1.x == p2.x && p1.y == p2.y) return false; int a = (p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x); int b = (p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x); return a * b <= 0; } class Point { int x; int y; public Point(int x, int y) { super(); this.x = x; this.y = y; } } public Point[][] pointArray(int n) { Point[][] res = new Point[n][2]; for (int i = 0; i < n; i++) { res[i][0] = new Point(sc.nextInt(), sc.nextInt()); res[i][1] = new Point(sc.nextInt(), sc.nextInt()); } return res; } public static void main(String[] args) { new No_245().run(); } }