求助60分,不懂为什么处理越界?
查看原帖
求助60分,不懂为什么处理越界?
1128181
Evolution333楼主2023/11/24 21:27
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int n,m,k;
int x,y,o,p;
int cnt;
int a[5005][5005];

int main()
{
    cin>>n>>m>>k;

    while(m--)
    {
        scanf("%d%d",&x,&y);

        a[x][y] = 1;
        a[x-1][y] = 1;
        a[x-2][y] = 1;
        a[x+1][y] = 1;
        a[x+2][y] = 1;
        a[x][y-1] = 1;
        a[x][y-2] = 1;
        a[x][y+1] = 1;
        a[x][y+2] = 1;
        a[x-1][y-1] = 1;
        a[x+1][y-1] = 1;
        a[x-1][y+1] = 1;
        a[x+1][y+1] = 1;
    }

    while (k--)
    {
        scanf("%d%d",&o,&p);


            for (int i = o - 2; i <= o + 2; i++)
            {
                for (int j = p - 2; j <= p + 2; j++)
                    a[i][j] = 1;
            }

    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j] == 0) cnt++;


        }

    }

    cout<<cnt;

    return 0;

}




2023/11/24 21:27
加载中...