输入输出样例
样例1
输入
7
1 2
2 1
0 0
1 1
1 0
2 0
0 1
输出
0
0
1
0
0
样例2
输入
2
0 0
-100000 10
输出
0
0
0
0
0
样例3
输入
11
9 10
10 10
11 10
12 10
13 10
11 9
11 8
12 9
10 9
10 11
12 11
输出
0
2
1
0
0
题解一
遍历每一个的点,考察其是否符合回收站的要求,再计算其得分。总点数n的数据范围不大,但是坐标的范围比较大,因此不能用数组存储,用集合来存储。
100分。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
final int[] DISX_1 = new int[] { 0, 0, -1, 1 };
final int[] DISY_1 = new int[] { -1, 1, 0, 0 };
final int[] DISX_2 = new int[] { -1, 1, -1, 1 };
final int[] DISY_2 = new int[] { -1, -1, 1, 1 };
final int DIR_NUM = 4;
BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(scanner.readLine());
Set<Point> set = new HashSet<>();
String[] strs;
for (int i = 0; i < n; ++i) {
strs = scanner.readLine().trim().split(" ");
set.add(new Point(Integer.parseInt(strs[0]), Integer.parseInt(strs[1])));
}
int[] ans = new int[5];
Point temp = new Point();
int junk;
int score;
for (Point p : set) {
junk = 0;
for (int i = 0; i < DIR_NUM; ++i) {
temp.x = p.x + DISX_1[i];
temp.y = p.y + DISY_1[i];
if (set.contains(temp)) {
++junk;
} else {
break;
}
}
if (junk == 4) {
score = 0;
for (int i = 0; i < DIR_NUM; ++i) {
temp.x = p.x + DISX_2[i];
temp.y = p.y + DISY_2[i];
if (set.contains(temp)) {
++score;
}
}
++ans[score];
}
}
for (int i = 0; i < 5; ++i) {
System.out.println(ans[i]);
}
}
}
class Point {
int x;
int y;
public Point() {
super();
}
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Point) {
Point p = (Point) obj;
return (x == p.x) && (y == p.y);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}