题目:
分析
此题的解题步骤可以分为三步:
1.判断(x,y)位置有无垃圾
2.判断该位置的上、下、左、右位置是否有垃圾
3.在满足2的前提下,判断该位置左上、左下、右上、右下四个位置是否有垃圾
对于案例1,只有点(1,1)复合条件2,且其对角线点有两个
对于案例3
其有三个点符合条件2,且对角线点为2的有1个,对角线点为1的有2个
同时,虽然题目的x,y的数据范围为|1e9|,但n的数据范围为1000,所以我们用结构体将这些数据存起来,然后遍历判断即可
代码
#include <bits/stdc++.h>
using namespace std;
int n;
int c[5];
struct sa{
int x1,y1;
}p[1005];
int main()
{
ios::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
p[i].x1=x;
p[i].y1=y;
}
if(n<=4)
//如果n<4,则永远不可能存在满足条件的点
{
printf("0\n0\n0\n0\n0\n");
}
else
{
for(int i=1;i<=n;i++)
//遍历数组,如果有符合特殊点的点就标记起来
{
int x=p[i].x1;
int y=p[i].y1;
int up=0,down=0,left=0,right=0,ul=0,ur=0,dl=0,dr=0;
for(int j=1;j<=n;j++)
{
int xp=p[j].x1;
int yp=p[j].y1;
if(xp==x-1&&yp==y)//上
{
up=1;
}
if(xp==x+1&&yp==y)//下
{
down=1;
}
if(xp==x&&yp==y+1)//左
{
right=1;
}
if(xp==x&&yp==y-1)//右
{
left=1;
}
if(xp==x-1&&yp==y-1)//上左
{
ul=1;
}
if(xp==x+1&&yp==y+1)//下右
{
dr=1;
}
if(xp==x-1&&yp==y+1)//上右
{
ur=1;
}
if(xp==x+1&&yp==y-1)//下左
{
dl=1;
}
}
if(up&&down&&left&&right)//如果上下左右四个点满足
{
int cnt=0;
if(ul==1)//如果对角线点满足
{
cnt++;
}
if(ur==1)
{
cnt++;
}
if(dl==1)
{
cnt++;
}
if(dr==1)
{
cnt++;
}
c[cnt%5]++;
}
}
for(int i=0;i<5;i++)
{
printf("%d\n",c[i]);
}
}
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
*/