以下为100分代码,仅供参考。
题目链接
C++代码
#include<bits/stdc++.h>
using namespace std;
int ans[5];
set<pair<int,int>> s;
set<pair<int,int>> s1;
pair<int,int> p1;
bool is(int x,int y)//判断这个对是否存在
{
s1.insert(make_pair(x,y));
if(s1.size()>s.size())
{
s1.erase(make_pair(x,y));//不存在 并且删除刚才插入的对
return false;
}
return true;
}
int main()
{
int n;
int a,b;
cin>>n;
for( int i=1;i<=n;i++ )
{
cin>>a>>b;
p1.first=a;
p1.second=b;
s.insert(p1);
s1.insert(p1);
}
for( auto it=s.begin();it!=s.end();it++ )
{
int x,y;
x=it->first;
y=it->second;
if( is(x+1,y)&&is(x-1,y)&&is(x,y-1)&&is(x,y+1) )//上下左右均存在垃圾
{
int cnt=0;
cnt=is(x+1,y+1) + is(x-1,y-1) + is(x+1,y-1) + is(x-1,y+1);//四个对角位置垃圾总数 range(0,4)
ans[cnt]++;
}
}
for( int i=0;i<5;i++ )
{
cout<<ans[i]<<endl;
}
return 0;
}
/*
7
1 2
2 1
0 0
1 1
1 0
2 0
0 1
11
9 10
10 10
11 10
12 10
13 10
11 9
11 8
12 9
10 9
10 11
12 11
*/