问题描述
试题编号: | 201912-2 |
试题名称: | 回收站选址 |
时间限制: | 1.0s |
内存限制: | 512.0MB |
问题描述: | 题目描述: 输入描述: 输出描述: 输入样例: 样例转载自https://blog.csdn.net/Nothing_but_Fight/article/details/103591317 |
算是用了一种比较笨的方法 用结构体数组压缩图 然后遍历所有点 查看是否可以建站 如果可以 计算得分
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const long long mul = 1e9;
const long long chen = 1e10;
const int N = 1000+5;
struct Node{
long long x;
long long y;
};
Node graph[N];
int ans[5];
int find(long long x,long long y,int n){
for(int i = 0; i < n;i++){
if(x == graph[i].x && y ==graph[i].y)
return 1;
}
return 0;
}
void slove(int n){
int temp,t1,t2,t3,t4;
for(int i = 0; i < n;i++){
long long x = graph[i].x;
long long y = graph[i].y;
//判断是否可以建站
t1 = find(x-1,y,n);
t2 = find(x+1,y,n);
t3 = find(x,y+1,n);
t4 = find(x,y-1,n);
temp = t1+t2+t3+t4;
if(temp!=4)
continue;
t1 = find(x+1,y+1,n);
t2 = find(x+1,y-1,n);
t3 = find(x-1,y+1,n);
t4 = find(x-1,y-1,n);
ans[t1+t2+t3+t4]++;
}
}
int main(){
int n;
long long a,b;
scanf("%d",&n);
for(int i = 0; i < n;i++){
scanf("%lld%lld",&a,&b);
graph[i].x=a;
graph[i].y=b;
}
memset(ans,0,sizeof(ans));
slove(n);
for(int i = 0;i<5;i++){
printf("%d\n",ans[i]);
}
}