結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-12 15:10:50 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,249 bytes |
| コンパイル時間 | 3,371 ms |
| コンパイル使用メモリ | 80,180 KB |
| 実行使用メモリ | 51,044 KB |
| 最終ジャッジ日時 | 2025-08-12 15:12:48 |
| 合計ジャッジ時間 | 7,509 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 18 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static class Point {
long x, y;
Point(long x, long y) {
this.x = x;
this.y = y;
}
}
// 计算两点之间距离的平方
private static long distSq(Point p1, Point p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
// 检查三点是否共线
// 使用叉积原理避免除法和浮点数:(y2-y1)*(x3-x2) == (y3-y2)*(x2-x1)
private static boolean areCollinear(Point p1, Point p2, Point p3) {
return (p2.y - p1.y) * (p3.x - p2.x) == (p3.y - p2.y) * (p2.x - p1.x);
}
public static void solve() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T-- > 0) {
StringTokenizer stA = new StringTokenizer(br.readLine());
Point a = new Point(Long.parseLong(stA.nextToken()), Long.parseLong(stA.nextToken()));
StringTokenizer stB = new StringTokenizer(br.readLine());
Point b = new Point(Long.parseLong(stB.nextToken()), Long.parseLong(stB.nextToken()));
StringTokenizer stC = new StringTokenizer(br.readLine());
Point c = new Point(Long.parseLong(stC.nextToken()), Long.parseLong(stC.nextToken()));
StringTokenizer stD = new StringTokenizer(br.readLine());
Point d = new Point(Long.parseLong(stD.nextToken()), Long.parseLong(stD.nextToken()));
// 1. 退化检查:任意三点共线则不是有效四边形
// 这个检查也包含了任意两点重合的情况
if (areCollinear(a, b, c) || areCollinear(b, c, d) || areCollinear(c, d, a) || areCollinear(d, a, b)) {
System.out.println("NONE");
continue;
}
// 2. 平行四边形判定:对角线中点是否重合
// (a.x + c.x)/2 == (b.x + d.x)/2 => a.x + c.x == b.x + d.x
// (a.y + c.y)/2 == (b.y + d.y)/2 => a.y + c.y == b.y + d.y
boolean isParallelogram = (a.x + c.x == b.x + d.x) && (a.y + c.y == b.y + d.y);
if (isParallelogram) {
long dAB2 = distSq(a, b);
long dBC2 = distSq(b, c);
long dAC2 = distSq(a, c);
long dBD2 = distSq(b, d);
boolean adjacentSidesEqual = (dAB2 == dBC2); // 菱形特性
boolean diagonalsEqual = (dAC2 == dBD2); // 矩形特性
if (adjacentSidesEqual && diagonalsEqual) {
System.out.println("SQUARE");
} else if (adjacentSidesEqual) {
System.out.println("RHOMBUS");
} else if (diagonalsEqual) {
System.out.println("RECTANGLE");
} else {
System.out.println("PARALLELOGRAM");
}
} else {
System.out.println("QUADRILATERAL");
}
}
}
public static void main(String[] args) throws IOException {
solve();
}
}