70分求调,样例全对,7、8、10WA

P11228 [CSP-J 2024] 地图探险

nowornever0625 @ 2024-10-26 22:31:32

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;

char Map[N][N];
bool vis[N][N];

int main() {
    //d=0东 1南 2西 3北
//  freopen("tmp.in", "r", stdin);
    int T;
    int n, m, k, x0, y0, d0, ans, x, y, d;
    cin >> T;
    while (T--) {
        memset(vis, 0, sizeof(vis));
        cin >> n >> m >> k >> x0 >> y0 >> d0;
        for (int i = 1; i <= n; i++) {
            string a;
            cin >> a;
            for (int j = 1; j <= m; j++)
                Map[i][j] = a[j - 1];
        }
        x = x0, y = y0, d = d0;
        while (k--) {
//          cout << x << y << ' ' << k << endl;
            ans = 0;
            vis[x][y] = 1;
            if (d == 0) {
                if (Map[x][y + 1] == '.')
                    y++, vis[x][y] = 1;
                else {
                    d = (d + 1) % 4;
                    continue;
                }
            }
            if (d == 1) {
                if (Map[x + 1][y] == '.')
                    x++, vis[x][y] = 1;
                else {
                    d = (d + 1) % 4;
                    continue;
                }
            }
            if (d == 2) {
                if (Map[x][y - 1] == '.')
                    y--, vis[x][y] = 1;
                else {
                    d = (d + 1) % 4;
                    continue;
                }
            }
            if (d == 3) {
                if (Map[x - 1][y] == '.')
                    x--, vis[x][y] = 1;
                else {
                    d = (d + 1) % 4;
                    continue;
                }
            }
        }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                ans += vis[i][j];
        cout << ans << endl;
    }
    return 0;
}

by ShenShi_Yan @ 2024-10-26 22:56:20

@xiaokang_suancai 我找找。。


by xiaokang_suancai @ 2024-10-26 22:57:55

@RloveY 哦哦明白了,thx


by xiaokang_suancai @ 2024-10-26 22:58:57

@RloveY 这有点搞人,按题意写赛时样例都过了没注意呃呃呃


by ShenShi_Yan @ 2024-10-26 23:00:02

@xiaokang_suancai 2

2 3 3

1 1 0

...

...

1 2 10

1 2 0

.

. 我自己造的,有点极端。。还没试过,理论上应该会hack住


by ShenShi_Yan @ 2024-10-26 23:01:10

@xiaokang_suancai 我也是。。当时第五个大样例都过了,也没多想,样例里也没有hack数据


上一页 |