70pts求条

P11228 [CSP-J 2024] 地图探险

SerenityWay @ 2024-11-05 21:10:41

考试时写的,当时以为可以AC,结果只得了70。WA on #5 #7 #10
代码:

#include <bits/stdc++.h>
using namespace std;
char c[1005][1005]={'x'};
int main(){
    //freopen("explore.in","r",stdin);
    //freopen("explore.out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n,m,k,x,y,d,s=1;//s表示步数,由于初始格也算所以初始化为1
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=1;i<=n;i++){//输入
            for(int j=1;j<=m;j++){
                cin>>c[i][j];
            }
        }
        while(k--){
            c[x][y]=',';//标记搜索过
            if(d==0){//判断
                if(c[x][y+1]=='.'){
                    y++,s++;
                }else if(c[x][y+1]==','){
                    y++;
                }else{
                    d=1;
                }
            }else if(d==1){
                if(c[x+1][y]=='.'){
                    x++,s++;
                }else if(c[x+1][y]==','){
                    x++;
                }else{
                    d=2;
                }
            }else if(d==2){
                if(c[x][y-1]=='.'){
                    y--,s++;
                }else if(c[x][y-1]==','){
                    y--;
                }else{
                    d=3;
                }
            }else if(d==3){
                if(c[x-1][y]=='.'){
                    x--,s++;
                }else if(c[x-1][y]==','){
                    x--;
                }else{
                    d=0;
                }
            }
        }
        cout<<s<<"\n";
    }
    return 0;
}

哪个大佬帮忙degug一下让我死心


by Lyx8058 @ 2024-11-05 21:13:43

s改成零


by Lyx8058 @ 2024-11-05 21:14:05

@luogu_cod


by LUJINGYU @ 2024-11-05 21:15:47

@Lyx8058 同意+1


by SerenityWay @ 2024-11-05 21:16:07

@Lyx8058 那不就爆0了嘛


by SerenityWay @ 2024-11-05 21:16:43

@LUJINGYU 直接改成0就全WA了啊


by SerenityWay @ 2024-11-05 21:18:23

@LUJINGYU @Lyx8058 那要怎么改


by Lyx8058 @ 2024-11-05 21:22:05

@luogu_cod 关键是你没判断边界啊


by SerenityWay @ 2024-11-05 21:22:46

@Lyx8058 留了边界的啊,数组设的1005而且全部初始化为x了


by Lyx8058 @ 2024-11-05 21:23:34

我意思是搜索的时候判断x,y有没有越界


by SerenityWay @ 2024-11-05 21:24:23

@Lyx8058 好吧我先改个几分钟


| 下一页