CSP2019-12(二)回收站选址
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long LL;
using namespace std;
struct point {
int x;
int y;
}trash[1010];
bool judge1(int x,int y,int n){
for(int i=0;i<n;i++){
if(trash[i].x==x&&trash[i].y==y){
return true;
}
}
return false;
}
int main()
{
int n;
scanf("%d",&n);
int x,y;
int a[5]={0};//输出的5行数
for(int i=0;i<n;i++){
scanf("%d%d",&x,&y);
trash[i].x=x;
trash[i].y=y;
}
for(int i=0;i<n;i++){
if(judge1(trash[i].x,trash[i].y,n)){
if(judge1(trash[i].x+1,trash[i].y,n)&&judge1(trash[i].x-1,trash[i].y,n)&&judge1(trash[i].x,trash[i].y+1,n)&&judge1(trash[i].x,trash[i].y-1,n)){
int num=0;
if(judge1(trash[i].x+1,trash[i].y+1,n))num++;
if(judge1(trash[i].x+1,trash[i].y-1,n))num++;
if(judge1(trash[i].x-1,trash[i].y+1,n))num++;
if(judge1(trash[i].x-1,trash[i].y-1,n))num++;
a[num]++;
}
}
}
for(int i=0;i<5;i++){
cout<<a[i]<<endl;
}
}