第一次题解
import java.util.Scanner;
public class csp2 {
public static void main(String[] args){
// 1 2
// 2 1
// 0 0
// 1 1
// 1 0
// 2 0
// 0 1
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] x = new int[n];
int[] y = new int[n];
int[] score_result = new int[5];
//输入
for(int i =0;i<n;i++){
x[i] = input.nextInt();
y[i] = input.nextInt();
}
//评分
for(int i =0;i<n;i++){
int score = 0;
//检查该处是否有垃圾
if (check(x[i], y[i], x, y)) {
// System.out.println(x[i]+" "+y[i]);
//如果有 判断是否可选址
if (check(x[i]-1, y[i], x, y) && check(x[i]+1, y[i], x, y) && check(x[i], y[i]-1, x, y) && check(x[i], y[i]+1, x, y)) {
//可选址则进行评分
if (check(x[i]-1, y[i]-1, x, y)) {
score++;
}
if (check(x[i]-1, y[i]+1, x, y)) {
score++;
}
if (check(x[i]+1, y[i]-1, x, y)) {
score++;
}
if (check(x[i]+1, y[i]+1, x, y)) {
score++;
}
if (score == 0)
score_result[0]++;
if (score == 1)
score_result[1]++;
if (score == 2)
score_result[2]++;
if (score == 3)
score_result[3]++;
if (score == 4)
score_result[4]++;
}
}
}
//输出结果
for(int i =0;i<5;i++){
System.out.println(score_result[i]);
}
}
public static boolean check(int x, int y, int[] X, int[] Y){
int leng = X.length;
for(int i =0;i<leng;i++){
if(x == X[i] && y == Y[i])
return true;
}
return false;
}
}