样例都没过······
查看原帖
样例都没过······
602555
封禁用户楼主2022/7/26 10:46
#include <iostream>
#include <queue>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int dx[] = { 1,1,2,2,2,2,-1,-1,-2,-2,-2,-2 };
int dy[] = { -2,2,-2,-1,1,2,-2,2,-1,1,-2,2 };
int x_1, y_1, x_2, y_2;
bool vis[25][25];
struct Firefox {
    int x, y, step;
};
int bfs(int sx, int sy) {
    queue<Firefox> q;
    memset(vis, 0, sizeof(vis));
    Firefox cur = { sx , sy , 0 };
    vis[sx][sy] = true;
    q.push(cur);
    while (!q.empty()) {
        cur = q.front();
        q.pop();
        if (cur.x == 1 && cur.y == 1) return cur.step;
        for (int i = 0; i <= 11; i++) {
            int nx = cur.x + dx[i];
            int ny = cur.y + dy[i];
            if (nx >= 1 && nx <= 25 && ny >= 1 && ny <= 25 && !vis[nx][ny]) {
                Firefox nxt = { nx , ny , cur.step + 1 };
                vis[nx][ny] = true;
                q.push(nxt);
            }
        }
    }
    return -1;
}
int main()
{
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    cout << bfs(x_1, y_1) << endl;
    cout << bfs(x_1, y_1) << endl;
    return 0;
}

有没有dalao康康哪里不对啊

2022/7/26 10:46
加载中...