作者:its_ycm
来源:CSDN
原文:https://blog.csdn.net/its_ycm/article/details/110224659
版权声明:本文为博主原创文章,转载请附上博文链接!
试题编号: 201912-2
试题名称: 回收站选址
时间限制: 1.0s
内存限制: 512.0MB
输入
7
1 2
2 1
0 0
1 1
1 0
2 0
0 1
2
0 0
-100000 10
11
9 10
10 10
11 10
12 10
13 10
11 9
11 8
12 9
10 9
10 11
12 11
这个方法空间使用太大,有待优化
#include<bits/stdc++.h>
using namespace std;
const int N =1000;
struct node{
int x,y;
}nod[N];
int main()
{
int n,t=0,a[5]={0,0,0,0,0};
cin >> n;
for(int i=0; i<n; ++i)
cin >> nod[i].x >> nod[i].y;
for(int i=0; i<n; ++i){
t=0;
for(int j=0; j<n; ++j)
{
if( nod[i].x==nod[j].x && nod[i].y==nod[j].y-1 )
t++;
if( nod[i].x==nod[j].x && nod[i].y==nod[j].y+1 )
t++;
if( nod[i].x==nod[j].x+1 && nod[i].y==nod[j].y )
t++;
if( nod[i].x==nod[j].x-1 && nod[i].y==nod[j].y )
t++;
if(t==4)
break;
}
if(t==4)
{
int k=0;
for(int j=0; j<n; ++j)
{
if( nod[i].x==nod[j].x-1 && nod[i].y==nod[j].y-1 )
k++;
if( nod[i].x==nod[j].x-1 && nod[i].y==nod[j].y+1 )
k++;
if( nod[i].x==nod[j].x+1 && nod[i].y==nod[j].y-1 )
k++;
if( nod[i].x==nod[j].x+1 && nod[i].y==nod[j].y+1 )
k++;
}
a[k]++;
}
}
for(int i=0; i<5; ++i)
cout << a[i] << endl;
return 0;
}