40分求调

P11228 [CSP-J 2024] 地图探险

zms20130313 @ 2024-11-03 11:26:06

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e3+5;
long long t,n,m,k,x,y,d;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
char mp[N][N];
int vis[N][N];
int main()
{
    cin>>t;
    while(t--){
        int res=1;
        memset(vis,0,sizeof vis);
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                cin>>mp[i][j];
            }
        }
        vis[x][y]=1;
        while(k--){
            int nx=x+dx[d];
            int ny=y+dy[d];
            if(nx<1||nx>n||ny<1||mp[nx][ny]=='x'){
                d=(d+1)%4;
            }
            else{
                x=nx;
                y=ny;
                if(!vis[x][y]){
                    res++;
                    vis[x][y]=1;
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


by Im_Joker @ 2024-11-03 11:31:22

@zms20130313 球管

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e3+5;
long long t,n,m,k,x,y,d;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
char mp[N][N];
int vis[N][N];
int main()
{
    cin>>t;
    while(t--){
        int res=1;
        memset(vis,0,sizeof vis);
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                cin>>mp[i][j];
            }
        }
        vis[x][y]=1;
        while(k--){
            int nx=x+dx[d];
            int ny=y+dy[d];
            if(nx<1||nx>n||ny<1||ny>m||mp[nx][ny]=='x'){
                d=(d+1)%4;
            }
            else{
                x=nx;
                y=ny;
                if(!vis[x][y]){
                    res++;
                    vis[x][y]=1;
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

by zms20130313 @ 2024-11-03 11:33:12

@Im_Joker 谢谢


by axy2414fujingze @ 2024-11-03 12:05:27

不是,你们是怎么看懂这么长的题目的


by fyc201908 @ 2024-11-03 14:26:33

@axy2414fujingze 提炼关键信息 加油吧


|