有大佬能看看我 40 分 代码哪出问题了吗

P11228 [CSP-J 2024] 地图探险

Ahws_rwhy @ 2024-10-26 20:27:58

#include <bits/stdc++.h>
using namespace std;
#define int long long
int t;
int n, m, k;
int x, y, d;
char mp[1001][1001];
int flag[1001][1001];
int ans;
signed main() {
    cin >> t;
    while (t--) {
        memset(flag,0,sizeof flag);
        ans = 0;
        cin >> n >> m >> k;
        cin >> x >> y >> d;
        int nowx = x, nowy = y;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> mp[i][j];
            }
        }
        while (k > 0) {
            if (d == 0) {
                k--;
                nowx = nowx, nowy = nowy + 1;
                if (nowx > n || nowy < 1 || nowx < 1 || nowy > m) {
                    d = (d + 1) % 4;
                    nowy = nowy - 1;
            //      continue;
                }
                if (mp[nowx][nowy] == '.' && d == 0 && flag[nowx][nowy] == 0) {
                    ans++;
                    flag[nowx][nowy] = 1;
                }
                if (mp[nowx][nowy] == 'x' && d == 0) {
                    d = (d + 1) % 4;
                    nowy = nowy - 1;
                }
            }
            if (d == 1) {
                k--;
                nowx = nowx + 1, nowy = nowy;
                if (nowx > n || nowy < 1 || nowx < 1 || nowy > m) {
                    d = (d + 1) % 4;
                    nowx = nowx - 1;
                //  continue;
                }
                if (mp[nowx][nowy] == '.' && d == 1 && flag[nowx][nowy] == 0) {
                    ans++;
                    flag[nowx][nowy] = 1;
                }
                if (mp[nowx][nowy] == 'x' && d == 1) {
                    d = (d + 1) % 4;
                    nowx = nowx - 1;
                }
            }
            if (d == 2) {
                k--;
                nowx = nowx, nowy = nowy - 1;
                if (nowx > n || nowy < 1 || nowx < 1 || nowy > m) {
                    d = (d + 1) % 4;
                    nowy = nowy + 1;
                //  continue;
                }
                if (mp[nowx][nowy] == '.' && d == 2 && flag[nowx][nowy] == 0) {
                    ans++;
                    flag[nowx][nowy] = 1;
                }
                if (mp[nowx][nowy] == 'x' && d == 2) {
                    d = (d + 1) % 4;
                    nowy = nowy + 1;
                }
            }
                if (d == 3) {
                    k--;
                    nowx = nowx - 1, nowy = nowy;
                    if (nowx > n || nowy < 1 || nowx < 1 || nowy > m) {
                        d = (d + 1) % 4;
                        nowx = nowx + 1;
                    //  continue;
                    }
                    if (mp[nowx][nowy] == '.' && d == 3 && flag[nowx][nowy] == 0) {
                        ans++;
                        flag[nowx][nowy] = 1;
                    }
                    if (mp[nowx][nowy] == 'x' && d == 3) {
                    //  k--;
                        d = (d + 1) % 4;
                        nowx = nowx + 1;
                    }
                }
        }
        if(1 <= x && x <= n && 1 <= y && y <= m) ans++;
        cout << ans << endl;
    }
    return 0;
}

by hyl2718281828 @ 2024-10-26 20:52:17

6,我看了这么半天没看出来,惭愧惭愧


上一页 |