80分,是哪里有问题,求指点。
查看原帖
80分,是哪里有问题,求指点。
1585376
Zhouyiyijoey楼主2025/2/3 18:42
#include <iostream>
using namespace std;
int main()
{
    int n,m,k;
    int x,y,n_x,n_y,o,p,n_o,n_p;
    int i,j,cn=0;
    int a[100][100];
    int t[13][2]={{-2,0},{-1,1},{-1,0},{-1,-1},{0,2},{0,1},{0,0},{0,-1},{0,-2},{1,1},{1,0},{1,-1},{2,0}};
    int f[25][2]={{-2, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-2, 2},
        {-1, -2}, {-1, -1}, {-1, 0}, {-1, 1}, {-1, 2},
        {0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2},
        {1, -2}, {1, -1}, {1, 0}, {1, 1}, {1, 2},
        {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2}};
    cin>>n>>m>>k;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            a[i][j]=0;
        }
    }
    for(i=1;i<=m;i++){
        cin>>x>>y;
        x--;
        y--;
        for(j=0;j<13;j++){
            n_x=x+t[j][0];
            n_y=y+t[j][1];
            if(n_x>=0||n_x<=n||n_y>=0||n_y<=n){
                a[n_x][n_y]=1;
            }
        }
    }
    for(i=0;i<k;i++){
        cin>>o>>p;
        o--;
        p--;
        for(j=0;j<25;j++){
            n_o=o+f[j][0];
            n_p=p+f[j][1];
            if(n_o>=0||n_o<=n||n_p>=0||n_p<=n){
                a[n_o][n_p]=1;
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(a[i][j]==0){
                cn++;
            }
        }
    }
    cout<<cn;
    return 0;
}
2025/2/3 18:42
加载中...