社区讨论

WA 40PTS,求调

P11228[CSP-J 2024] 地图探险参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mkgouxr2
此快照首次捕获于
2026/01/16 17:41
上个月
此快照最后确认于
2026/01/18 20:45
上个月
查看原帖
CODE:
CPP
#include <iostream>
using namespace std;
const int MAXN = 1e3 + 5;
char a[MAXN][MAXN];
bool vis[MAXN][MAXN];
int n,m,k,x,y,d;
bool check(int x,int y){
    if (x < 1 || x > n || y < 1 || y > m)return false;
    if (a[x][y] == 'x')return false;
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--){
        cin >> n >> m >> k >> x >> y >> d;
        int ans = 1;
        vis[x][y] = 1;
        for (int i = 1;i <= n;i++)for (int j = 1;j <= m;j++)cin >> a[i][j];
        for (int i = 1;i <= n;i++){
            fill(vis[i] + 1,vis[i] + MAXN + 1,false);
        }
        while (k--){
            int testx = x,testy = y;
            switch (d){
                case 0 : testy++;break;
                case 1 : testx++;break;
                case 2 : testy--;break;
                case 3 : testx--;break;
            }
            if (check(testx,testy) && !vis[testx][testy]){
                x = testx;
                y = testy;
                vis[x][y] = true;
                ans++;
            }
            else d = (d + 1) % 4;
        }
        cout << ans << "\n";
    }
    return 0;
}
请大家指出,哪里有不对呢?

回复

2 条回复,欢迎继续交流。

正在加载回复...