求助 B 题的爆搜全 WA
查看原帖
求助 B 题的爆搜全 WA
574944
Micnation_AFO楼主2022/7/23 18:03
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };
const int N = 1e3 + 5;

struct coord {
    int x, y;
};

int T;
string s[N];
queue<coord> q;
bool vis[N][N];

bool value(int x, int y, int n, int m) {
    if (x > n || y > m) return true;
    if (x < 0 || y < 0) return true;
    return false;
}

int main() {
    cin >> T;
    while (T--) {
        int n, m, k; bool flag = false;
        cin >> n >> m; while (q.size()) q.pop(); memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= n; i++) cin >> s[i];
        cin >> k;
        coord sta, fin;
        cin >> sta.x >> sta.y >> fin.x >> fin.y;
        q.push(sta); vis[sta.x][sta.y] = true;
        while (q.size()) {
            coord l = q.front(); q.pop();
            if (l.x == fin.x && l.y == fin.y) {
                cout << "T\n";
                flag = true;
                break;
            }
            for (int i = 0; i < 4; i++) {
                int x = l.x + dx[i], y = l.y + dy[i];
                if (value(x, y, n, m) || vis[x][y]) continue;
                vis[x][y] = true;
                coord val; val.x = x, val.y = y;
                q.push(val);
            }
        }
        if (!flag) cout << "F\n"; 
    }
    return 0;
}

2022/7/23 18:03
加载中...