1. 程式人生 > 實用技巧 >CCF--201912-2 回收站選址

CCF--201912-2 回收站選址



#include<iostream>
using namespace std;

struct node{
    int x;
    int y;
    int flag = 0;
    int score = 0;
}node;


int main(){
    int n;
    cin >> n;
    struct node arr[n];
    int scores[5] = {0,0,0,0,0};
    for(int i = 0; i < n; i++){
        cin >> arr[i].x >> arr[i].y;
    }
    int x0, y0;
    //check
    for(int i = 0; i < n; i++){
        x0 = arr[i].x;
        y0 = arr[i].y;
        for(int j = 0; j < n; j++){
            if(x0 == arr[j].x && (y0+1) == arr[j].y){
                arr[i].flag ++;
            }
            if(x0 == arr[j].x && (y0-1) == arr[j].y){
                arr[i].flag ++;
            }
            if((x0+1) == arr[j].x && y0 == arr[j].y){
                arr[i].flag ++;
            }
            if((x0-1) == arr[j].x && y0 == arr[j].y){
                arr[i].flag ++;
            }

            if((x0+1) == arr[j].x && (y0+1) == arr[j].y){
                arr[i].score ++;
            }
            if((x0-1) == arr[j].x && (y0-1) == arr[j].y){
                arr[i].score ++;
            }
            if((x0+1) == arr[j].x && (y0-1) == arr[j].y){
                arr[i].score ++;
            }
            if((x0-1) == arr[j].x && (y0+1) == arr[j].y){
                arr[i].score ++;
            }
        }
        if(arr[i].flag == 4){
            scores[arr[i].score] ++;
        }

    }


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



}

害,打幾個迴圈就能出來的事,我當初卻只有0分,真是太drama了