样例全过但70分,求

P11228 [CSP-J 2024] 地图探险

mc_xiexie @ 2024-11-09 10:36:31

#include<bits/stdc++.h>
using namespace std;
int mapp[1005][1005];
int main(){
    //freopen("explore5.in","r",stdin);
    int T;
    cin>>T;
    while(T--){
        int n,m,k,x,y,d,ex=0,ey=0,sum=1;
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                if(c=='.'){
                    mapp[i][j]=1;
                }
                else{
                    mapp[i][j]=0;
                }
            }
        }
        if(d==0){
            ex=0;ey=1;
        }
        if(d==1){
            ex=1;ey=0;
        }
        if(d==2){
            ex=0;ey=-1;
        }
        if(d==3){
            ex=-1;ey=0;
        }
        mapp[x][y]=2;
        while(k--){
            if(mapp[x+ex][y+ey]){
                if(mapp[x+ex][y+ey]==1){
                    mapp[x+ex][y+ey]=2;sum++;
                }
                x+=ex;y+=ey;
            }
            else{
                d++;
                if(d%4==0){
                    ex=0;ey=1;
                }
                if(d%4==1){
                    ex=1;ey=0;
                }
                if(d%4==2){
                    ex=0;ey=-1;
                }
                if(d%4==3){
                    ex=-1;ey=0;
                }
            }
        }
        cout<<sum<<"\n";
    }
}

by mc_xiexie @ 2024-11-09 10:38:44

大致思路是模拟,走过的格子标为 2,没走过且能走的格子sum++


by mc_xiexie @ 2024-11-09 10:49:10

此帖结,没判边界


|