其他分享
首页 > 其他分享> > CCF 201912-2 回收站选址

CCF 201912-2 回收站选址

作者:互联网

作者:its_ycm 
来源:CSDN 
原文:https://blog.csdn.net/its_ycm/article/details/110173292
版权声明:本文为博主原创文章,转载请附上博文链接!

试题编号: 201912-2
试题名称: 回收站选址
时间限制: 1.0s
内存限制: 512.0MB
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
这个方法空间使用太大,有待优化

#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;
} 

标签:nod,++,int,&&,201912,CCF,回收站
来源: https://blog.csdn.net/its_ycm/article/details/110224659