CSP 201912 第二题——回收站选址

题目要求

CSP 201912 第二题——回收站选址_第1张图片
CSP 201912 第二题——回收站选址_第2张图片CSP 201912 第二题——回收站选址_第3张图片

思路

当该点的上下左右有一个没有出现在输入中,都不能算是安装垃圾桶的考虑范围。所以先判断上下左右是否都出现,再判断对角线是否出现。

代码

#include 
#include 
using namespace std;
const int maxn=1e4;
typedef struct node{
     
               int x,y;
               int r,l,u,d;
               int score;
}node;
node book[maxn];
int main()
{
     
    int n;
    cin>>n;
    int ans[5]={
     0};
    for(int i=0;i<n;i++){
     
               cin>>book[i].x>>book[i].y;
               book[i].score=0;
    }
    for(int i=0;i<n;i++){
     
               for(int j=0;j<n;j++){
     
                              if(book[i].x==book[j].x&&book[i].y==book[j].y-1){
     
                                             book[i].l=1;
                              }
                              if(book[i].x==book[j].x&&book[i].y==book[j].y+1){
     
                                             book[i].r=1;
                              }
                              if(book[i].x==book[j].x+1&&book[i].y==book[j].y){
     
                                             book[i].u=1;
                              }
                              if(book[i].x==book[j].x-1&&book[i].y==book[j].y){
     
                                             book[i].d=1;
                              }
                              if(book[i].x==book[j].x-1&&book[i].y==book[j].y-1){
     
                                             book[i].score++;
                              }
                              if(book[i].x==book[j].x+1&&book[i].y==book[j].y-1){
     
                                             book[i].score++;
                              }
                              if(book[i].x==book[j].x+1&&book[i].y==book[j].y+1){
     
                                             book[i].score++;
                              }
                              if(book[i].x==book[j].x-1&&book[i].y==book[j].y+1){
     
                                             book[i].score++;
                              }
               }
               if(book[i].d==1&&book[i].l==1&&book[i].r==1&&book[i].u==1){
     
                              ans[book[i].score]++;
               }

    }
    for(int i=0;i<5;i++){
     
                              cout<<ans[i]<<endl;
               }
    return 0;
}

你可能感兴趣的:(CSP 201912 第二题——回收站选址)