70pts求调

P11228 [CSP-J 2024] 地图探险

wenxinran @ 2024-10-27 20:13:03

样例全部AC

7#8#10未过

#include<bits/stdc++.h>
using namespace std;
int t;
char a[1005][1005];
bool vis[1005][1005];
int main(){
//  freopen("P11228.in","r",stdin);
//  freopen("P11228.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        int n,m,k,ans=0;
        scanf("%d %d %d",&n,&m,&k);
        for(int i=1;i<=1005;i++){
            for(int j=1;j<=1005;j++){
                vis[i][j]=0;
                a[i][j]=' ';
            }
        }
//      printf("-1\n");
        int x,y,d;
        scanf("%d %d %d",&x,&y,&d);
        vis[x][y]=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        while(k--){
            int xx,yy;
            if(d==0) xx=x,yy=y+1;
            else if(d==1) xx=x+1,yy=y;
            else if(d==2) xx=x,yy=y-1;
            else if(d==3) xx=x-1,yy=y;
            if(a[xx][yy]!='.') d=(d+1)%4;
            else x=xx,y=yy;
            vis[x][y]=1;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(vis[i][j]==1) ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

by wenxinran @ 2024-10-27 20:23:25

此帖结,未判边界


by xujingbo @ 2024-10-27 20:23:29

if时要判断边界,而且d=(d+1)%4;后直接continue


by ctzm @ 2024-10-27 20:30:33

char a[1005][1005];
bool vis[1005][1005];
for(int i=1;i<=1005;i++){
  for(int j=1;j<=1005;j++){
    vis[i][j]=0;
    a[i][j]=' ';
  }
}

确认不越界?


by pjr_freopen @ 2024-10-27 21:15:40

@xujingbo 但她这个初始化为空格了啊


|