70分求助

P11228 [CSP-J 2024] 地图探险

Mcfire05 @ 2024-10-27 16:08:21

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int qwq[1145][1145];
int main(){
    //freopen("explore4.in","r",stdin);
    //freopen("explore4.out","w",stdout);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n,m,k,ans=0;
        cin>>n>>m>>k;
        int robx,roby,robd;
        cin>>robx>>roby>>robd;
        char robmap[n+5][m+5];
        for(int j=1;j<=n;j++){
            for(int iii=1;iii<=m;iii++){
                cin>>robmap[j][iii];
            }
        }
        qwq[robx][roby]=1;
        for(int j=0;j<k;j++){
            if(robd==0 and roby+1<=m and robmap[robx][roby+1]!='x'){
                roby++;
                qwq[robx][roby]=1;
            }else if((robd==0 and roby+1>m) or (robmap[robx][roby+1]=='x' and robd==0)){
                int jkdf=robd;
                robd=(jkdf+1)%4;
                continue;
            }
            if(robd==1 and robx+1<=n and robmap[robx+1][roby]!='x'){
                robx++;
                qwq[robx][roby]=1;
            }else if((robd==1 and robx+1>n) or (robmap[robx+1][roby]=='x' and robd==1)){
                int jkdf=robd;
                robd=(jkdf+1)%4;
                continue;
            }
            if(robd==2 and roby-1>=1 and robmap[robx][roby-1]!='x'){
                roby--;
                qwq[robx][roby]=1;
            }else if((robd==2 and roby-1<1) or (robmap[robx][roby-1]=='x' and robd==2)){
                int jkdf=robd;
                robd=(jkdf+1)%4;
                continue;
            }
            if(robd==3 and robx-1>=1 and robmap[robx-1][roby]!='x'){
                robx--;
                qwq[robx][roby]=1;
            }else if((robd==3 and roby-1<1) or (robmap[robx-1][roby]=='x' and robd==3)){
                int jkdf=robd;
                robd=(jkdf+1)%4;
                continue;
            }
        }
        for(int j=1;j<=n;j++){
            for(int iii=1;iii<=m;iii++){
                ans+=qwq[j][iii];
            }
        }
        for(int j=1;j<=n;j++){
            for(int iii=1;iii<=m;iii++){
                qwq[j][iii]=0;
            }
        }
        cout<<ans<<'\n';
    }
}

考场上样例4能过,现在不知道为啥过不了了


|