玄大关,求大调

P11228 [CSP-J 2024] 地图探险

zyx_dzpd @ 2024-11-08 11:21:28

#include<bits/stdc++.h>
using namespace std;

int n,m,p,i,j,d,k,x,y,l=0;
char a[1001][1001];

void dp(){
    l=1;
    while(1){
        if(d==0){
            if(y+1>=1 and y+1<=m and a[x][y+1]!='x'){
                //if(a[x][y]!='y')
                l++;
                a[x][y]='y';
                y++;
                d=(d+1)%4;
                k--;
            cout<<"0 ";
            }
            else d=(d+1)%4,k--;
        }
        else if(d==1){
            if(x+1>=1 and x+1<=n and a[x+1][y]!='x'){
                //if(a[x][y]!='y') 
                l++;
                a[x][y]='y';
                x++;
                d=(d+1)%4;
                k--;
            cout<<"1 ";
            }
            else d=(d+1)%4,k--;
        }
        else if(d==2){
            if(y-1>=1 and y-1<=m and a[x][y-1]!='x'){
                //if(a[x][y]!='y') 
                l++;
                a[x][y]='y';
                y--;
                d=(d+1)%4;
                k--;
            cout<<"2 ";
            }
            else d=(d+1)%4,k--;
        }
        else if(d==3){
            if(x-1>=1 and x-1<=n and a[x-1][y]!='x'){
                //if(a[x][y]!='y') 
                l++;
                a[x][y]='y';
                x--;
                d=(d+1)%4;
                k--;
            cout<<"3 ";
            }
            else d=(d+1)%4,k--;
        }
        if(k<=0) return ;
//      cout<<"x:"<<x<<"  y:"<<y<<" k:"<<k<<" d:"<<d<<"\n";
    }
}

int main(){
//  freopen("1.in","r",stdin);
//  freopen("1.out","w",stdout);
    int T;
    cin>>T;
    for(i=1;i<=T;i++){
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(j=1;j<=n;j++){
            for(p=1;p<=m;p++){
                cin>>a[j][p];
            }
        }
        dp();
    /*  for(j=1;j<=n;j++){
            for(p=1;p<=m;p++){
                cout<<a[j][p]<<" ";
            }
            cout<<"\n";
        }*/
        cout<<l<<"\n";
    }
    return 0;
}

by yangyuhan_yyh @ 2024-11-08 20:35:27

#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d,b[1001][1001];
char a[1001][1001];
int main(){
    int t;cin>>t;
    for(int q=1;q<=t;q++){
        long long sum=0,ans=0;
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];b[i][j]=0;
                if(a[i][j]=='.')ans++;
            }
        }b[x][y]=1;
        while(k>0&&ans>0){
            while((k>0)&&((d==0&&a[x][y+1]=='x')||(d==1&&a[x+1][y]=='x')||(d==2&&a[x][y-1]=='x')||(d==3&&a[x-1][y]=='x')||(d==0&&y+1>m)||(d==1&&x+1>n)||(d==2&&y-1<=0)||(d==3&&x-1<=0))){
                d=(d+1)%4,k--;
            }if(d==0)y++;
            else if(d==1)x++;
            else if(d==2)y--;
            else if(d==3)x--;
            k--;if(k>=0){
                b[x][y]++;
                if(b[x][y]==1)ans--;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(b[i][j]!=0)sum++;
            }
        }cout<<sum<<endl;
    }
    return 0;
}

@zyx_dzpd


by Are_you_sure_cjj @ 2024-11-08 21:04:45

#include<bits/stdc++.h>
using namespace std;
char M[1005][1005];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int vis[1005][1005];
int main(){
    int T,n,m,cnt,k,x,y,d,ny,nx;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=0;i<1005;i++)
            for(int j=0;j<1005;j++)
                M[i][j]='x',vis[i][j]=0;

        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++){
                cin>>M[i][j];
            }
        cnt=1;
        vis[x][y]=1;
        while(k--){
            nx=x+dx[d],ny=y+dy[d];
            if(M[nx][ny]=='x'){d=(d+1)%4;continue;}
            x=nx,y=ny;
            if(!vis[x][y]) vis[x][y]=1,cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

|