求调(玄关)

P11228 [CSP-J 2024] 地图探险

wind_city_Rose @ 2024-10-26 19:42:41

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+10;
char c[maxn][maxn];
long long vis[maxn][maxn]={};
long long t,n,m,k,x,y,d;
int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m>>k>>x>>y>>d;
        long long cnt=0;
        for(int i=1;i<=n;i++){
            cin>>c[i];
        }
        vis[x][--y]=1;
        while(k--){
            int nx,ny;
            if(d==0){
                nx=x,ny=y+1;
            }if(d==1){
                nx=x+1,ny=y;
            }if(d==2){
                nx=x,ny=y-1;
            }if(d==3){
                nx=x-1,ny=y;
            }
            if(c[nx][ny]=='x'||nx<1||nx>n||ny<0||ny>=m){
                d=(d+1)%4;
            }else{
                x=nx,y=ny;
                vis[x][y]=1;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=0;j<m;j++){
                if(vis[i][j]==1) cnt++;
            }
        }
        cout<<cnt<<endl;
    }   
 return 0;
}

哪错了,样例过了


by jerrychen2013 @ 2024-10-26 19:52:20

vis数组没初始化,有t组数据


by jerrychen2013 @ 2024-10-26 19:57:21

@wind_city_Rose 在吗,试了下,改完能A

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+10;
char c[maxn][maxn];
long long vis[maxn][maxn]={};
long long t,n,m,k,x,y,d;
int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m>>k>>x>>y>>d;
        long long cnt=0;
        for(int i=1;i<=n;i++){
            cin>>c[i];
        }
        vis[x][--y]=1;
        while(k--){
            int nx,ny;
            if(d==0){
                nx=x,ny=y+1;
            }if(d==1){
                nx=x+1,ny=y;
            }if(d==2){
                nx=x,ny=y-1;
            }if(d==3){
                nx=x-1,ny=y;
            }
            if(c[nx][ny]=='x'||nx<1||nx>n||ny<0||ny>=m){
                d=(d+1)%4;
            }else{
                x=nx,y=ny;
                vis[x][y]=1;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=0;j<m;j++){
                if(vis[i][j]==1) cnt++;
                vis[i][j]=0;
            }
        }
        cout<<cnt<<endl;
    }   
 return 0;
}

by wind_city_Rose @ 2024-10-26 20:42:19

@jerrychen2013 谢谢大佬


|