60pts WA on 6-10求调

P11228 [CSP-J 2024] 地图探险

zhaiyaokun_chouzi @ 2024-10-31 17:40:45

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
int t;
struct node{
    int x,y;
    int d;
}robot;
struct node1{
    int x,y;
}linshi;
char a[N][N];
int v[N][N];
int main(){
    cin>>t;
    for(int l=1;l<=t;l++){
        int n,m,k;
        cin>>n>>m>>k;
        cin>>robot.x>>robot.y>>robot.d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        linshi.x=robot.x;
        linshi.y=robot.y;
        int cnt=1;
        memset(v,0,sizeof v);
        v[robot.x][robot.y]=1;
        while(k--){
            if(robot.d==0)
                linshi.y++;
            else if(robot.d==1)
                linshi.x++;
            else if(robot.d==2)
                linshi.y--;
            else if(robot.d==3)
                linshi.x--;
            if(linshi.x<1||linshi.x>n||linshi.y<1||linshi.y>m||a[linshi.x][linshi.y]=='x'){
                robot.d=(robot.d+1)%4;
                linshi.x=robot.x;
                linshi.y=robot.y;
                continue;
            }
            else{
                if(v[linshi.x][linshi.y]==0&&a[linshi.x][linshi.y]=='.'){
                    robot.x=linshi.x;
                    robot.y=linshi.y;
                    v[linshi.x][linshi.y]=1;
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

by mysb @ 2024-10-31 21:29:49

方向不一样能重复走 @ zhaiyaokun_chouzi


by zhaiyaokun_chouzi @ 2024-11-02 19:00:08

好的谢谢


|