結果
| 問題 |
No.202 1円玉投げ
|
| コンテスト | |
| ユーザー |
thorikawa
|
| 提出日時 | 2015-05-03 23:59:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,304 ms / 5,000 ms |
| コード長 | 2,471 bytes |
| コンパイル時間 | 2,928 ms |
| コンパイル使用メモリ | 80,376 KB |
| 実行使用メモリ | 76,716 KB |
| 最終ジャッジ日時 | 2024-12-22 06:40:47 |
| 合計ジャッジ時間 | 32,110 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
import java.util.*;
public class Main {
static class Point {
int x;
int y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
double dist(Point o) {
return Math.sqrt((this.x - o.x) * (this.x - o.x) + (this.y - o.y) * (this.y - o.y));
}
@Override
public String toString() {
return "(" + this.x + ", " + this.y + ")";
}
}
static int getId(int x, int y) {
return x * 1001 + y;
}
static int[] dirx = new int[]{0, 1, 0, -1, 0, 1, 1, -1, -1};
static int[] diry = new int[]{0, 0, 1, 0, -1, 1, -1, 1, -1};
public static void main(String[] argv) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int res = 0;
Map<Integer, List<Point>> data = new HashMap<Integer, List<Point>>();
for (int i = 0; i < n; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
Point p = new Point(x, y);
x /= 20;
y /= 20;
boolean overwrap = false;
for (int j = 0; j < dirx.length; j++) {
int nx = dirx[j] + x;
int ny = diry[j] + y;
if (nx < 0 || ny < 0 || nx > 1001 || ny > 1001) continue;
int newKey = getId(nx, ny);
if (data.containsKey(newKey)) {
List<Point> points = data.get(newKey);
for (Point p2 : points) {
// System.out.println("compare:" + p.toString() + " : " + p2.toString());
if (p.dist(p2) < 20) {
// System.out.println("overwrap!!");
overwrap = true;
break;
}
}
}
if (overwrap) {
break;
}
}
if (!overwrap) {
List<Point> list;
int id = getId(x, y);
if (data.containsKey(id)) {
list = data.get(id);
} else {
list = new ArrayList<Point>();
data.put(id, list);
}
// System.out.println("add:" + id + ":" + p.toString());
res++;
list.add(p);
}
}
System.out.println(res);
}
}
thorikawa