40 RE求调!!

P11228 [CSP-J 2024] 地图探险

cd230119czy @ 2024-10-30 21:08:14

#include<bits/stdc++.h>
using namespace std;
int cs;
int m,n,k;
int p[2010][2010];
bool s[2010][2010]= {false};
string tmp[100];
int qwq(int n,int m,int k) {
    int x,y,d;
    int ans=1;
    //cin
    cin>>x>>y>>d;
    for(int i=1; i<=n; i++) {
        cin>>tmp[i];
        tmp[i]='!'+tmp[i];
        for(int j=1; j<=m; j++) {
            if(tmp[i][j]=='.') {
                p[i][j]=0;
            } else {
                p[i][j]=1;
            }
        }
    }
    //RUNING
    s[x][y]=true;
    for(int i=1; i<=k; i++) {
        if(d==0) {
            if(y+1<=m&&(p[x][y+1]!=1)) {
                y+=1;
                if(s[x][y]!=true) {
                    s[x][y]=true;
                    ans+=1;
                }
            } else {
                d=1;
            }
        } else if(d==1) {
            if(x+1<=n&&(p[x+1][y]!=1)) {
                x+=1;
                if(s[x][y]!=true) {
                    s[x][y]=true;
                    ans+=1;
                }
            } else {
                d=2;
            }
        } else if(d==2) {
            if(y-1>=1&&(p[x][y-1]!=1)) {
                y-=1;
                if(s[x][y]!=true) {
                    s[x][y]=true;
                    ans+=1;
                }
            } else {
                d=3;
            }
        } else if(d==3) {
            if(x-1>=1&&(p[x-1][y]!=1)) {
                x-=1;
                if(s[x][y]!=true) {
                    s[x][y]=true;
                    ans+=1;
                }
            } else {
                d=0;
            }
        }
    }
    return ans;
}

int main() {
//  freopen("explore.in","r",stdin);
//  freopen("explore.out","w",stdout);
    cin>>cs;
    for(int i=1;i<=cs;i++){
        cin>>n>>m>>k;
        memset(s,0,sizeof(s));
        memset(p,0,sizeof(p));
        cout<<qwq(n,m,k)<<endl;
    }
    return 0;
}

测试样例二输入到一半就未响应


by Ff472130 @ 2024-10-30 21:10:46

字符串数组开小了


by yuanshiren_qidong @ 2024-10-30 21:11:43

tmp数组开小了


by cd230119czy @ 2024-10-31 14:17:19

谢谢,AC了


|