結果
問題 | No.245 貫け! |
ユーザー |
![]() |
提出日時 | 2015-07-19 21:38:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 247 ms / 5,000 ms |
コード長 | 1,592 bytes |
コンパイル時間 | 3,580 ms |
コンパイル使用メモリ | 77,760 KB |
実行使用メモリ | 42,244 KB |
最終ジャッジ日時 | 2024-07-08 10:27:17 |
合計ジャッジ時間 | 8,043 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
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(); } }