不知哪错了,求大佬指教

P11228 [CSP-J 2024] 地图探险

sshhgggddsbf @ 2024-11-02 00:12:18

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,k,x,y,d;
const int N=1e4+10;
char a[N][N];
bool dist[N][N];
void ct(int n){
    if(n==0)cout<<"东"<<endl;
    if(n==1)cout<<"南"<<endl;
    if(n==2)cout<<"西"<<endl;
    if(n==3)cout<<"北"<<endl;
}//调试
signed main(){
cin>>t;
while(t--){
    memset(dist,0,sizeof dist);
    cin>>n>>m>>k>>x>>y>>d;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    dist[x][y]=1;
    a[x][y]='!';
    while(k--){
        if(d==0){
            y++;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;
                a[x][y]='!';
            }else{
                d=(d+1)%4;
                y--;
            }
        }
        else if(d==1){
            x++;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                x--;
            }
        }
        else if(d==2){
            y--;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                y++;
            }
        }
        else if(d==3){
            x--;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                x++;
            }
        }//ct(d);cout<<" "<<x<<" "<<y<<" "<<k<<endl;(调试) 
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='!')ans++;
        //  cout<<a[i][j];(调试)
        }//cout<<endl;(调试)
    }
    cout<<ans<<endl;
}

return 0;
}

by MCsky @ 2024-11-02 07:51:01


#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,k,x,y,d;
const int N=1e4+10;
char a[N][N];
bool dist[N][N];
void ct(int n){
    if(n==0)cout<<"东"<<endl;
    if(n==1)cout<<"南"<<endl;
    if(n==2)cout<<"西"<<endl;
    if(n==3)cout<<"北"<<endl;
}//调试
signed main(){
cin>>t;
while(t--){
    memset(dist,0,sizeof dist);
    cin>>n>>m>>k>>x>>y>>d;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    dist[x][y]=1;
    a[x][y]='!';
    while(k--){
        if(d==0){
            y++;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;
                a[x][y]='!';
            }else{
                d=(d+1)%4;
                y--;
            }
        }
        else if(d==1){
            x++;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                x--;
            }
        }
        else if(d==2){
            y--;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                y++;
            }
        }
        else if(d==3){
            x--;
            if(a[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m){
                dist[x][y]=1;a[x][y]='!';
            }else{
                d=(d+1)%4;
                x++;
            }
        }\ 
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='!')ans++;
        }
    }
    cout<<ans<<endl;
}

return 0;
}

by sshhgggddsbf @ 2024-11-15 14:19:48

@MCsky?貌似没过,40分(前四个测试点对了)


|