大佬求助,有两个点超时!!!!!
查看原帖
大佬求助,有两个点超时!!!!!
957640
Michelle01楼主2023/7/30 19:17
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;

int pp[1010][1010];

int main() {

    int ans = 0;
    int sum = 0;
    int n, huo, ying, x, y, q, s;
    cin >> n >> huo >> ying;
    for(int i = 0; i < huo; i++){
        cin >> x >> y;
        pp[x][y] = 1;
        pp[x][y - 1] = 1;
        pp[x][y - 2] = 1;
        pp[x][y + 1] = 1;
        pp[x][y + 2] = 1;
        pp[x - 1][y - 1] = 1;
        pp[x + 1][y - 1] = 1;
        pp[x - 2][y] = 1;
        pp[x - 1][y] = 1;
        pp[x + 1][y] = 1;
        pp[x + 2][y] = 1;
        pp[x - 1][y + 1] = 1;
        pp[x + 1][y + 1] = 1;
    }
    for(int i = 0; i < ying; i++){
        cin >> q >> s;
        pp[q][s] = 1;
        pp[q][s - 1] = 1;
        pp[q][s - 2] = 1;
        pp[q][s + 1] = 1;
        pp[q][s + 2] = 1;
        pp[q - 1][s - 2] = 1;
        pp[q - 2][s - 2] = 1;
        pp[q + 1][s - 2] = 1;
        pp[q + 2][s - 2] = 1;
        pp[q - 1][s - 1] = 1;
        pp[q - 2][s - 1] = 1;
        pp[q + 1][s - 1] = 1;
        pp[q + 2][s - 1] = 1;
        pp[q - 1][s] = 1;
        pp[q - 2][s] = 1;
        pp[q + 1][s] = 1;
        pp[q + 2][s] = 1;
        pp[q - 1][s + 1] = 1;
        pp[q - 2][s + 1] = 1;
        pp[q + 1][s + 1] = 1;
        pp[q + 2][s + 1] = 1;
        pp[q - 1][s + 2] = 1;
        pp[q - 2][s + 2] = 1;
        pp[q + 1][s + 2] = 1;
        pp[q + 2][s + 2] = 1;
    } 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(pp[i][j] != 1){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
2023/7/30 19:17
加载中...