50求解

P11228 [CSP-J 2024] 地图探险

lileyang123 @ 2024-10-26 16:45:23

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t; 
bool f[1010][1010];
char a[1010][1010];
signed main(){
    cin>>t;
    for(int i=1;i<=t;i++){
        memset(a,0,sizeof(a));
        memset(f,0,sizeof(f));
        int n,m,k,cnt=1;
        cin>>n>>m>>k;
        int x,y,d;
        cin>>x>>y>>d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
            }
        } 
        while(k--){

            if(d==0){
                y+=1;
            }else if(d==1){
                x+=1;
            }else if(d==2){
                y-=1;
            }else {
                x-=1;
            }if(f[x][y]==1){
                continue;
            }
            if(a[x][y]!='.'&&a[x][y]!='x'){
                if(d==0){
                    y-=1;
                }else if(d==1){
                    x-=1;
                }else if(d==2){
                    y+=1;
                }else {
                    x+=1;
                }d+=1;
                d%=4; 
                continue;
            }if(a[x][y]=='x'){
                if(d==0){
                    y-=1;
                }else if(d==1){
                    x-=1;
                }else if(d==2){
                    y+=1;
                }else {
                    x+=1;
                }d+=1;
                d%=4; 
                continue;
            }
            if(f[x][y]==0){
                cnt++;
                f[x][y]=1;
            }
        }cout<<cnt<<endl;
    }
    return 0;
}

|