201912-2回收站选址
作者:互联网
题目描述
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, direct[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}, a[5];
set<pair<int, int>> garbage;
memset(a, 0, sizeof(a));
cin >> n;
for(int i = 0; i < n; i++){
int x, y;
cin >> x >> y;
pair<int, int> p(x, y);
garbage.insert(p);
}
for(auto it = garbage.begin(); it != garbage.end(); it++){
int flag = 1;
for(int i = 0; i < 4; i++){
pair<int, int> tmp(it->first + direct[i][0], it->second + direct[i][1]);
if(garbage.find(tmp) == garbage.end()){
flag = 0;
break;
}
}
if(flag == 1){
flag = 0;
for(int i = 4; i < 8; i++){
pair<int, int> tmp(it->first + direct[i][0], it->second + direct[i][1]);
if(garbage.find(tmp) != garbage.end())
flag++;
}
a[flag]++;
}
}
for(int i = 0; i < 5; i++)
cout << a[i] << '\n';
return 0;
}
/*
7
1 2
2 1
0 0
1 1
1 0
2 0
0 1
*/
如果对各位看官有帮助不妨留下一个点赞 ̄ω ̄=。
标签:tmp,garbage,int,direct,++,flag,201912,选址,回收站 来源: https://blog.csdn.net/weixin_51621643/article/details/120579462