考试时样例全过,Windows下无法正常运行

P11228 [CSP-J 2024] 地图探险

TianKeMing @ 2024-10-26 17:50:08

rt,代码如下(根据记忆写下的)

#include <bits/stdc++.h>
using namespace std;
int solve(int n, int m, int k, int x, int y, int d, char map[1001][1001]) {
    int sum = 0;
    int f[1002][1002];
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= m + 1; j++) {
            if (map[i][j] == '.') f[i][j] = 0;
            else f[i][j] = -1;
        }
    }
    f[x][y] = 1;
    for (int i = 1; i <= k; i++) {
        if (d == 0) {
            if (f[x][y + 1] == -1) {
                d = (d + 1) % 4;
                continue;
            }
            y++;
            f[x][y + 1] = 1;
            continue;
        }
        if (d == 1) {
            if (f[x + 1][y] == -1) {
                d = (d + 1) % 4;
                continue;
            }
            x++;
            f[x + 1][y] = 1;
            continue;
        }
        if (d == 2) {
            if (f[x][y - 1] == -1) {
                d = (d + 1) % 4;
                continue;
            }
            y--;
            f[x][y - 1] = 1;
            continue;
        }
        if (d == 3) {
            if (f[x - 1][y] == -1) {
                d = (d + 1) % 4;
                continue;
            }
            x--;
            f[x - 1][y] = 1;
            continue;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (f[i][j] == 1) sum++;
        }
    }
    return sum;
}
int main(){
    int T, N[6], M[6], K[6], X[6], Y[6], D[6], ans[6];
    char MAP[6][1001][1001];
    cin >> T;
    for (int a = 1; a <= T; a++) {
        cin >> N[a] >> M[a] >> K[a] >> X[a] >> Y[a] >> D[a];
        for (int i = 1; i <= N[a]; i++) {
            for (int j = 1; j <= M[a]; j++) cin >> MAP[a][i][j];
        }
        ans[a] = solve(N[a], M[a], K[a], X[a], Y[a], D[a], MAP[a]);
    }
    for (int i = 1; i <= T; i++) cout << ans[i];
    return 0;
}

经排查,是数组MAP[6][1001][1001]出了问题,是范围定义太大了吗?考试时在NOI Linux2.0环境下编译,样例全过,运行没有问题,有人知道问题吗?


by 4041nofoundGeoge @ 2024-10-26 17:54:47

@TianKeMing 这道题是模拟,不是搜索

#include<bits/stdc++.h>
using namespace std;
char s[1005][1005];
bool vis[1005][1005];
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int n,m,k,x0,d0,y0;
int main(){
    freopen("explore.in","r",stdin);
    freopen("explore.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        memset(vis,0,sizeof(vis));
        memset(s,0,sizeof(s));      
        cin>>n>>m>>k>>x0>>y0>>d0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                cin>>s[i][j];
        int cnt=1;
        int now=d0,nx=1,ny=1;
        vis[nx][ny]=1;
        for(int i=1;i<=k;i++){
            int tx=dx[now]+nx,ty=dy[now]+ny;
            if(tx<=n&&tx>=1&&ty<=m&&ty>=1&&s[tx][ty]=='.'){
                nx=tx,ny=ty;
                if(vis[nx][ny]==0)cnt++;
                vis[nx][ny]=1;
            }else{
                now=(now+1)%4;
            }
        }
        cout<<cnt<<"\n";
    }
    return 0;
}//求关

by huang1019 @ 2024-10-26 17:57:23

@4041nofoundGeoge 最后一个样例把代码卡没了 555 rp++


by kimi0809 @ 2024-10-26 18:01:04

@4041nofoundGeoge 嗯嗯


by TianKeMing @ 2024-10-26 18:03:37

@4041nofoundGeoge 不好意思,可能是我表述有误。我想问一下,为什么我的代码在考试时能正常运行,在个人PC上运行有问题?是我代码记错了吗?


by 4041nofoundGeoge @ 2024-10-26 18:05:01

@TianKeMing 估计是的


by Xuancheng_Mao @ 2024-10-26 19:03:12

map好像是保留关键字吧


by CNzzc @ 2024-10-26 22:17:54

@4041nofoundGeoge y0不会CE吗


by 4041nofoundGeoge @ 2024-10-26 22:20:25

@CNzzc 本地不会,洛谷有可能


by CNzzc @ 2024-10-26 22:22:41

@4041nofoundGeoge 我记得windows不会报,但是linux很容易就爆了


|