csp解题第二弹 2019-12第二题

用了个笨方法写,利用map的性质解决问题,对每个点先遍历上下左右判断是否是可用的垃圾点,若可用则判断斜对角是否有点存在来计算垃圾站点的分数。此题过了,感觉有点虚。。。欢迎交流指正

#include<iostream>
#include<map>
#include<stdio.h>
using namespace std;

pair<long long int,long long int> point[1001];
map<pair<long long int,long long int>,int> pos;//is exist
//map<pair<int,int>,int> pt;//fenshu


int main(){
	int ptcnt[5]={0,0,0,0,0};//
	int n;
	cin>>n;
	pair<long long int,long long int> test;
	for(int i=0;i<n;i++){
		cin>>point[i].first>>point[i].second;
		pos[point[i]]=2;
	}
	pair<long long int,long long int> suround[4];//up down left right
	pair<long long int,long long int> suround2[4];//(x+-1,y+-1)
	for(int i=0;i<n;i++){
		//pt[point[i]]=0;
		int cnt=0;//cnt=4???
		suround[0].first=point[i].first;
		suround[0].second=point[i].second+1;
		suround[1].first=point[i].first;
		suround[1].second=point[i].second-1;
		suround[2].first=point[i].first-1;
		suround[2].second=point[i].second;
		suround[3].first=point[i].first+1;
		suround[3].second=point[i].second;
		for(int j=0;j<4;j++){
			if(pos[suround[j]]==2){
				cnt++;
				//cout<<pos[suround[j]]<<",";
				//cout<<endl;
			}
		}
		//cout<<endl;
		if(cnt==4)//useful
		{
			//pt[point[i]]=0;
			int cu_pt=0;
			suround2[0].first=point[i].first+1;
			suround2[0].second=point[i].second+1;
			suround2[1].first=point[i].first+1;
			suround2[1].second=point[i].second-1;
			suround2[2].first=point[i].first-1;
			suround2[2].second=point[i].second-1;
			suround2[3].first=point[i].first-1;
			suround2[3].second=point[i].second+1;
			for(int j=0;j<4;j++)
				if(pos[suround2[j]]==2)
					cu_pt++;
				//cout	
			ptcnt[cu_pt]++;
		}
		
	}
	for(int i=0;i<5;i++)
		cout<<ptcnt[i]<<endl;

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值