日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

75: libreoj #10028 双向宽搜

發布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 75: libreoj #10028 双向宽搜 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

$des$

實現一個bfs

$sol$

寫了一個雙向bfs

#include <bits/stdc++.h>using namespace std;#define Rep(i, a, b) for(int i = a; i <= b; i ++)#define gc getchar() inline int read() {int x = 0; char c = gc;while(c < '0' || c > '9') c = gc;while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;return x; }const int N = 305; const int xd[] = {-1, -2, -2, -1, 1, 2, 2, 1}; const int yd[] = {-2, -1, 1, 2, 2, 1, -1, -2};int Lim = 300; int vis[N][N], bel[N][N]; int n; int Bfs_time; queue<pair <int, int> > Q;inline int Work(int sx, int sy, int tx, int ty) {if(sx == tx && sy == ty) return 0;memset(vis, 0, sizeof vis);memset(bel, 0, sizeof bel);while(!Q.empty()) Q.pop();Q.push(make_pair(sx, sy));Q.push(make_pair(tx, ty));bel[sx][sy] = 1, bel[tx][ty] = 2;vis[tx][ty] = 1;while(!Q.empty()) {pair <int, int> tp = Q.front();Q.pop();int px = tp.first, py = tp.second;Rep(i, 0, 7) {int nx = px + xd[i], ny = py + yd[i];if(bel[nx][ny] == bel[px][py] || nx < 0 || nx > Lim || ny < 0 || ny > Lim) continue;if(vis[nx][ny]) return vis[nx][ny] + vis[px][py];vis[nx][ny] = vis[px][py] + 1;bel[nx][ny] = bel[px][py];Q.push(make_pair(nx, ny));}} }int main() {n = read();while(n --) {Lim = read();cout << Work(read(), read(), read(), read()) << "\n"; }return 0; }

?

轉載于:https://www.cnblogs.com/shandongs1/p/9873579.html

總結

以上是生活随笔為你收集整理的75: libreoj #10028 双向宽搜的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。