本地没问题,luogu CE

P11228 [CSP-J 2024] 地图探险

Rich1 @ 2024-11-04 21:22:43

//T2
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define pre(i, a, b) for(int i = (a); i >= (b); --i)
#define mem(a, b) memset(a, b, sizeof(a))
#define de(a) cerr << #a << '=' << a << ' '
const int N = 1e3 + 10;
int T, n, m, k;
int x0, y0, d0;
char mp[N][N];
bool vis[N][N];
void init() {
    mem(mp, 0);
    mem(vis, 0);
}
void solve() {
    cin >> n >> m >> k >> x0 >> y0 >> d0;
    rep(i, 1, n) rep(j, 1, m)
        cin >> mp[i][j];
    int x = x0, y = y0, d = d0;
    while(k--)
    {
        vis[x][y] = true;
        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(xx < 1 || xx > n || yy < 1 || yy > m || mp[xx][yy] == 'x')
        {
            xx = x, yy = y;
            d = (d + 1) % 4;
            continue;
        }
        x = xx, y = yy;
        vis[xx][yy] = true;
    }
    int ans = 0;
    rep(i, 1, n) rep(j, 1, m)
        ans += vis[i][j];
    cout << ans << '\n';
}
int main() {
    freopen("explore.in", "r", stdin);
    freopen("explore.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> T;
    while(T--)
    {
        init();
        solve();
    }
    return 0;
}

by gghack_Nythix @ 2024-11-04 21:24:31

不能用y0,我也这样子T2挂0了


by LG086 @ 2024-11-04 21:25:19

@Rich1 死因:y0.


by Rich1 @ 2024-11-04 21:27:15

@LG086 谢谢


by LionBlaze @ 2024-11-04 21:30:17

@Rich1 默哀。。所以还是用局部变量或者 namespace


|