求助!!!!!!!!!!!!!!

P11228 [CSP-J 2024] 地图探险

fanshuangwei666 @ 2024-11-01 21:56:02

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char s[N][N];
int T,n,m,k,x_0,y_0,d_0,ans=1;
int vis[N][N];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool Check(int x,int y,int d){
    int tx=x+dx[d],ty=y+dy[d];
    if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&s[tx][ty]=='.'){
        x_0=tx,y_0=ty;
        return 1;
    }else{
        d_0=(d+1)%4;
        return 0;
    }
}
void Input(){
    cin>>n>>m>>k;
    cin>>x_0>>y_0>>d_0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s[i][j];
        }
    }
}
int main(){
    cin>>T;
    for(int i=1;i<=T;i++)
     Input();
     vis[x_0][y_0]=1;
     while(k--){
        if(Check(x_0,y_0,d_0)){
            if(vis[x_0][y_0]==0){
                ans++;
                vis[x_0][y_0]=1;
            }
        }
     }
    cout<<ans<<endl;
    ans=1;
    memset(vis,0,sizeof(vis));
    return 0;
}

by Phoenix114514 @ 2024-11-01 22:02:59

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char s[N][N];
int T,n,m,k,x_0,y_0,d_0,ans=1;
int vis[N][N];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool Check(int x,int y,int d){
    int tx=x+dx[d],ty=y+dy[d];
    if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&s[tx][ty]=='.'){
        x_0=tx,y_0=ty;
        return 1;
    }else{
        d_0=(d+1)%4;
        return 0;
    }
}
void Input(){
    cin>>n>>m>>k;
    cin>>x_0>>y_0>>d_0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s[i][j];
        }
    }
}
int main(){
    cin>>T;
    for(int i=1;i<=T;i++){
     Input();
     vis[x_0][y_0]=1;
     while(k--){
        if(Check(x_0,y_0,d_0)){
            if(vis[x_0][y_0]==0){
                ans++;
                vis[x_0][y_0]=1;
            }
        }
     }
    cout<<ans<<endl;
    ans=1;
    memset(vis,0,sizeof(vis));
    }
    return 0;
}

by Phoenix114514 @ 2024-11-01 22:03:34

@fanshuangwei666 找不同


by fanshuangwei666 @ 2024-11-02 13:41:58

@Phoenix114514 有个},谢谢你


|