版本比较
P4082 [USACO17DEC] Push a Box P 题解
正文
增加 8 行删除 8 行
67 行未改动68697071727273747475767778798080818283845 行未改动909192939494959697985 行未改动10410510610710810810911011111211311411511611711711811912012114 行未改动13613713813914014014114214314423 行未改动16816917017117217217317417517629 行未改动67 行未改动
## 代码
```cpp// 先Tarjan求出点双 // 先Tarjan求出点双// 然后dfs判断人能到哪里// 最后bfs求解 // 最后bfs求解#include<bits/stdc++.h>#define mk make_pairusing namespace std;const int maxn = 1505;// 行列上移动的方向,注意要和后面的 dfs 和 bfs 对应。const int WayX[] = {-1,0,1,0}; const int WayX[] = {-1,0,1,0};const int WayY[] = {0,-1,0,1};int n,m;char MP[maxn][maxn]; // 原图int dfn[maxn][maxn],low[maxn][maxn],clo;5 行未改动bool check(int x,int y) { // 判断是否越界/卡墙里 return x >= 1 && x <= n && y >= 1 && y <= m && MP[x][y] != '#';}// 暴力判断两点是否被同一点双包含bool checkSame(int ux,int uy,int vx,int vy) { bool checkSame(int ux,int uy,int vx,int vy) { for (auto x : b[ux][uy]) for (auto y : b[vx][vy]) if (x == y) return true; return false;5 行未改动 for (int w = 0;w < 4;w ++) { int vx = ux + WayX[w], vy = uy + WayY[w]; // 相邻点 if (!check(vx,vy)) continue; if (!dfn[vx][vy]) { Tarjan(vx,vy,ux,uy); Tarjan(vx,vy,ux,uy); low[ux][uy] = min(low[ux][uy],low[vx][vy]); if (low[vx][vy] >= dfn[ux][uy]) { // 发现割点 (ux,uy) b[ux][uy].push_back(++ tot); do { int x = st[top].first, y = st[top].second; b[x][y].push_back(tot); } while (st[top --] != mk(vx,vy)); } } else if (vx != fx || vy != fy) } else if (vx != fx || vy != fy) low[ux][uy] = min(low[ux][uy],dfn[vx][vy]); }}bool CanMove[4],DfsVis[maxn][maxn];14 行未改动int Q;bool BfsVis[maxn][maxn][4]; // 存状态,上文中提到过。bool Ans[maxn][maxn]; // 最终答案// Bfs 队列,前一个 pair 存 Bessie 的坐标,后一个 pair 存箱子的坐标。queue<pair<pair<int,int>,pair<int,int> > >Que; queue<pair<pair<int,int>,pair<int,int> > >Que;void Bfs() { pair<int,int> Box = mk(Bx,By); // 对处理出的结果往队列里扔初始的状态 for (int w = 0;w < 4;w ++) // 也要和 WayX,WayY 对应23 行未改动 Ans[i][j] = false; for (int k = 0;k < 4;k ++) Ans[i][j] |= BfsVis[i][j][k]; // 统计答案 }
}int main() { scanf("%d%d%d",&n,&m,&Q); for (int i = 1;i <= n;i ++) {29 行未改动