ccf201912-2回收站选址

◇◆丶佛笑我妖孽 提交于 2020-03-06 12:56:15
#include <stdio.h>
#include 
#include <string.h>
using namespace std;
#define N 1010
struct node{
int x, y;
}a[N];
node b[N], c[N], d[N];
int e[N];
bool cmp1(node a, node b){
if(a.x != b.x) return a.x < b.x;
else return a.y < b.y;
}
bool cmp2(node a, node b){
if(a.y != b.y) return a.y < b.y;
else return a.x < b.x;
}
int main(){
memset(e, 0, sizeof(e));
int n, i, j;
scanf("%d", &n);
for(i=0; i<n; ++i){
scanf("%d%d", &a[i].x, &a[i].y);
b[i].x = a[i].x; b[i].y = a[i].y;
}
sort(a, a+n, cmp1); sort(b, b+n, cmp2);
int k = 0;
for(i=1; i<n-1; ++i){
if(a[i-1].xa[i].x && a[i].xa[i+1].x && a[i-1].y+1a[i].y && a[i].ya[i+1].y-1){
c[k].x = a[i].x; c[k].y = a[i].y; ++k;
}
}
int h = 0;
for(i=1; i<n-1; ++i){
if(b[i-1].yb[i].y && b[i].yb[i+1].y && b[i-1].x+1b[i].x && b[i].xb[i+1].x-1){
d[h].x = b[i].x; d[h].y = b[i].y; ++h;
}
}
sort(d, d+h, cmp1);
int w = 0;
for(i=0; i<k; ++i){
for(j=0; j<h; ++j){
if(c[i].xd[j].x && c[i].yd[j].y){
b[w].x = c[i].x; b[w].y = c[i].y; ++w;
}
}
}
int count;
for(i=0; i<w; ++i){
count = 0;
for(j=0; j<n; ++j){
if(b[i].x+1 == a[j].x){
if(b[i].y+1 == a[j].y) count++;
if(b[i].y-1 == a[j].y) count++;
}
if(b[i].x-1 == a[j].x){
if(b[i].y+1 == a[j].y) count++;
if(b[i].y-1 == a[j].y) count++;
}
}
e[count]++;
}
for(i=0; i<=4; ++i){
printf("%d\n", e[i]);
}
return 0;
}
————————————————
版权声明:本文为CSDN博主「WOSHILURENJI」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/WOSHILURENJI/article/details/104607684
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!