版本比较
2026.9.23 模拟赛
正文
增加 73 行删除 0 行
83 行未改动84858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166168 行未改动全部展开83 行未改动```
## [T2. P1363 幻象迷宫](https://www.luogu.com.cn/problem/P1363)
这个图如果能无限走,当且仅当一个点在一个矩阵单元能走到,在另一个矩阵单元也能走到。
我们显然可以直接暴力 bfs,走到的点标记为 $1$,如果一个被标记为 $1$ 的、不在原来的矩阵单元的点取模后在原来的矩阵单元,那么就是 `Yes`。
否则就是 `No`。
这样我们去标点会 `MLE`,我们考虑对空间的优化。
考虑记录取模的 $(x,y)$ 为 $(mx,my)$,我们记录 $vis(mx,my)$ 为第一次到 $(mx,my)$ 的绝对坐标。
如果我们尝试第二次去更新 $vis(mx,my)$ 时,并且 $mx \not= x \lor my \not= y$,说明就是一个矩阵单元能走到,在另一个矩阵单元也能走到的情况,返回 `Yes`。
否则就是 `No`。
```cppconst int N = 1.5e3 + 2 ;const int dx[4] = {0,1,0,-1} ;const int dy[4] = {1,0,-1,0} ;int n,m ;int sx,sy ;char g[N][N] ;pair<int,int> vis[N][N] ;inline int modx (fi x) { re int ans = (x % n + n) % n ; if (ans == 0) ans = n ; return ans ;}inline int mody (fi y) { re int ans = (y % m + m) % m ; if (ans == 0) ans = m ; return ans ;}inline bool bfs (fi sx,fi sy) { queue<pair<int,int>> q ; q.push({sx,sy}) ; vis[sx][sy] = {sx,sy} ; while (q.size()) { pair<int,int> u = q.front() ;q.pop() ; int fx = u.first,fy = u.second ; for (re int i = 0 ; i < 4 ; ++i) { int xx = fx + dx[i],yy = fy + dy[i] ; int mx = modx(xx),my = mody(yy) ; if (g[mx][my] == '#') continue ; if (vis[mx][my] == make_pair(0,0)) { vis[mx][my] = {xx,yy} ; q.push({xx,yy}) ; } else if (vis[mx][my].first != xx || vis[mx][my].second != yy) return 1 ; } } return 0 ;}
inline void solve () { for (re int i = 1 ; i <= n ; ++i) { for (re int j = 1 ; j <= m ; ++j) { cin >> g[i][j] ; if (g[i][j] == 'S') sx = i,sy = j ; } } if (bfs(sx,sy)) cout << "Yes\n" ; else cout << "No\n" ; for (re int i = 1 ; i <= n ; ++i) { for (re int j = 1 ; j <= m ; ++j) vis[i][j] = {0,0} ; }}int main () { ios_base::sync_with_stdio(false) ; cin.tie(0),cout.tie(0) ; while (cin >> n >> m) solve() ; return 0 ;}```
## [T3. P1347 [ECNA 2001] 排序](https://www.luogu.com.cn/problem/P1347)
显然和 T1 一个题目。
168 行未改动全部展开