1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <iostream> #include <algorithm> using namespace std; struct coord { long long x, y; coord(){} coord(long long x, long long y) :x(x), y(y) {} bool operator == (const coord& coord2) const { return x == coord2.x && y == coord2.y; } bool operator < (const coord& coord2) const { if (x != coord2.x)return x < coord2.x; return y < coord2.y; } }arr[10005]; int n; int XArr[] = {0,0,1,-1,1,1,-1,-1}; int YArr[] = {1,-1,0,0,1,-1,1,-1}; int stat[5]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].x >> arr[i].y; sort(arr, arr + n); for (int i = 0; i < n; i++) { int cnter = 0; for (int j = 0; j < 4; j++) { coord tmp(arr[i].x + XArr[j], arr[i].y + YArr[j]); if (*lower_bound(arr, arr + n, tmp) == tmp) cnter++; } if (cnter != 4)continue; cnter = 0; for (int j = 4; j < 8; j++) { coord tmp(arr[i].x + XArr[j], arr[i].y + YArr[j]); if (*lower_bound(arr, arr + n, tmp) == tmp) cnter++; } stat[cnter]++; } for (int i = 0; i < 5; i++) { cout << stat[i] << "\n"; } } |
CSP 201912-2 回收站选址
发表评论