纯模拟20pts求助!!!

P11228 [CSP-J 2024] 地图探险

PigeonGame @ 2024-11-16 12:35:32

#include<bits/stdc++.h>
#define jiasu ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define jdsr for(int i=0;i<n;i++)  cin>>a[i];
#define jdsc for(int i=0;i<n;i++)  cout<<a[i]<<" ";
using namespace std;
int t;
char a[1005][1005];
bool b[1005][1005];
int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    jiasu;
    cin>>t;
    for(int i=1;i<=t;i++){
        int n,m,k,x,y,d,s=1;
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        b[x][y]=true;
        for(int j=1;j<=n;j++){
            for(int q=1;q<=m;q++){
                cin>>a[j][q];
            }
        }
        while(k--){
            if(d==0){
                if((x>=1&&x<=n)&&(y+1>=1&&y+1<=m)&&(a[x][y+1]=='.')){
                    y+=1;
                    if(b[x][y]==false){
                        s++;
                        b[x][y]=true;
                    }
                }else{
                    d=(d+1)%4;
                }
            }else if(d==1){
                if((x+1>=1&&x+1<=n)&&(y>=1&&y<=m)&&(a[x+1][y]=='.')){
                    x+=1;
                    if(b[x][y]==false){
                        s++;
                        b[x][y]=true;
                    }
                }else{
                    d=(d+1)%4;
                }
            }else if(d==2){
                if((x>=1&&x<=n)&&(y-1>=1&&y-1<=m)&&(a[x][y-1]=='.')){
                    y-=1;
                    if(b[x][y]==false){
                        s++;
                        b[x][y]=true;
                    }
                }else{
                    d=(d+1)%4;
                }
            }else if(d==3){
                if((x-1>=1&&x-1<=n)&&(y>=1&&y<=m)&&(a[x-1][y]=='.')){
                    x-=1;
                    if(b[x][y]==false){
                        s++;
                        b[x][y]=true;
                    }
                }else{
                    d=(d+1)%4;
                }
            }
        }
        cout<<s<<"\n";
    }
    return 0;
}

by WangSiHan_2011 @ 2024-11-16 12:39:49

多测不清空,爆零两行泪。


|