输入输出样例
样例1
输入
71 22 10 01 11 02 00 1
输出
00100
样例2
输入
20 0-100000 10
输出
00000
样例3
输入
119 1010 1011 1012 1013 1011 911 812 910 910 1112 11
输出
02100
题解一
遍历每一个的点,考察其是否符合回收站的要求,再计算其得分。总点数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;}@Overridepublic boolean equals(Object obj) {if (obj instanceof Point) {Point p = (Point) obj;return (x == p.x) && (y == p.y);}return false;}@Overridepublic int hashCode() {return Objects.hash(x, y);}}
