1 solutions

  • 0
    @ 2025-3-3 16:27:11

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    int mw[3][3],qp[10][9];
    int main(){
        memset(qp,0,sizeof(qp));
        int n,m,x,y,z,ans=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>mw[i][1]>>mw[i][2];
            qp[mw[i][1]][mw[i][2]]=3;
        }
        cin>>m;
        for(int i=1;i<=m;i++){
            cin>>x>>y>>z;
            qp[x][y]=z+1;
        }
        for(int i=1;i<=n;i++){
            x=mw[i][1];
            y=mw[i][2];
            if(y+2<=8&&qp[x][y+1]==0){
                if(qp[x+1][y+2]==2&&x+1<=9){
                    ans++;
                    qp[x+1][y+2]=1;
                }
                if(qp[x-1][y+2]==2&&x-1>=0){
                    ans++;
                    qp[x-1][y+2]=1;
                }
            }
            if(x-2>=0&&qp[x-1][y]==0){
                if(qp[x-2][y+1]==2&&y+1<=8){
                    ans++;
                    qp[x-2][y+1]=1;
                }
                if(qp[x-2][y-1]==2&&y-1>=0){
                    ans++;
                    qp[x-2][y-1]=1;
                }
            }
            if(y-2>=0&&qp[x][y-1]==0){
                if(qp[x+1][y-2]==2&&x+1<=9){
                    ans++;
                    qp[x+1][y-2]=1;
                }
                if(qp[x-1][y-2]==2&&x-1>=0){
                    ans++;
                    qp[x-1][y-2]=1;
                }
            }
            if(x+2<=9&&qp[x+1][y]==0){
                if(qp[x+2][y+1]==2&&y+1<=8){
                    ans++;
                    qp[x+2][y+1]=1;
                }
                if(qp[x+2][y-1]==2&&y-1>=0){
                    ans++;
                    qp[x+2][y-1]=1;
                }
            }
        }
        cout<<ans;
        return 0;
    }
    
    • 1

    Information

    ID
    10125
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By