0pts 蒟蒻求调

P11228 [CSP-J 2024] 地图探险

XiaoShenQAQ @ 2025-01-04 17:40:09

0pts 第一版

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
char map[1004][1004];
bool visit[1004][1004];
int dx[5]={0,1,0,-1},dy[5]={1,0,-1,0};
int T,d,k,n,m,all,x,y,xx,yy;
int main(){
/*  freopen("explore.in","r",stdin);
    freopen("explore.out","w",stdout);*/
    cin>>T;
    while(T--){
        memset(map,0,sizeof(map));
        memset(visit,0,sizeof(visit));
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>map[i][j];
            }
        }
        all=1;
        visit[x][y]=1;
        while(k--){
            xx=x+dx[d];
            yy=y+dy[d];
            if(map[xx][yy]=='.'){
                if(visit[xx][yy]==0){
                    visit[xx][yy]=1;
                    all++;
                }
                x=xx;
                y=yy;
            }else{
                d=(d+1)%4;
            }

        }
        cout<<all<<endl;
    }
}

全WA,样例1第二个输出14


by XiaoHongChong @ 2025-01-04 18:15:03

@XiaoShenQAQ 注意坐标,左上角是(1,1)

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
char map[1004][1004];
bool visit[1004][1004];
int dx[5]={0,1,0,-1},dy[5]={1,0,-1,0};
int T,d,k,n,m,all,x,y,xx,yy;
int main(){
/*  freopen("explore.in","r",stdin);
    freopen("explore.out","w",stdout);*/
    cin>>T;
    while(T--){
        memset(map,0,sizeof(map));
        memset(visit,0,sizeof(visit));
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=1;i<=n;i++){   /改这里
            for(int j=1;j<=m;j++){  //和这里
                cin>>map[i][j];
            }
        }
        all=1;
        visit[x][y]=1;
        while(k--){
            xx=x+dx[d];
            yy=y+dy[d];
            if(map[xx][yy]=='.'){
                if(visit[xx][yy]==0){
                    visit[xx][yy]=1;
                    all++;
                }
                x=xx;
                y=yy;
            }else{
                d=(d+1)%4;
            }

        }
        cout<<all<<endl;
    }
}

|