T693886 广度优先搜索数据生成

题目背景

[本题题解 1](https://www.luogu.me/article/z1ebduzv) 来自于[小黑屋小黑](https://www.luogu.com.cn/team/92915)的团队题目. 在`「BOI R16」国庆比赛II(A组)`中有这么一道题:`【模板】广度优先搜索[加强]`,这道题目是对于上述比赛题目的数据生成程序。 ### 已完工

题目描述

输入 $n$,请给出一个 $n \times n$ 的字符矩阵,其中只包含 `#` 和 `.` 两种字符,要求你所生成的字符矩阵能让传统的 `DFS` 卡住在 $1s$ 内,而可以让 `BFS` 通过 ( 不接受经过特殊优化的 `DFS` 而通过的代码 )。要求开始点坐标是 有序二元组 $(1,2) $ 和 $(n,n)$ 。(以 $1$ 开始,例如坐标 $(1,2)$ 代表第一行第二列)。 :::warning[警告] 本题只有一组评测数据,你可以按照下方提示作答,*不喜勿喷*,你可以去做其他的。如:https://www.luogu.com.cn/problem/P9145. 和本题近似。 ::::info[信息] 如果你实在忍不住(不喷难受的情况),欢迎找出题人[liangyl](https://www.luogu.com.cn/user/1054058) 5-5小时 $\frac{1}{4}$ 天对线(每日下午 15:00至 20:00) 本人上学。 :::::warning[免责声明]{open} 任何对线对于出题人不承担任何责任。 保证不违反《洛谷社区规则》。 不保证出题人不会给你骂到哭。 或顺着网线来找你。 ::::: ::::success[奖励] 如果你把 `liangyl` 骂破防了,他会给你人民币 $10.00$ 元 或者你 `AC` 了这道题,`liangyl`会给你 $e^{i \pi} + 1$ RMB。如有符合条件者,请私信。 (支付宝转账)。

输入格式

第一行一个正整数 $n$。 即输入完毕。

输出格式

一个 $n \times n$ 的字符矩阵,**符合题目描述的要求**。 :::error[特别警告!]{open} 本题的SPJ判分标准是选手给出的矩阵让DFS测试,当其走过步数超过迷宫总数的 $70\%$ 时即判过,否则 $\color{#E74C3C}\text{WA}$。

说明/提示

这里数据范围有些**奇怪**,注意开始坐标是 $(1,2)$ 。 # 数据范围 $1000 \leq n \leq 10000$。 保证输入合法。 # 提示 在样例里已经给出了这题的思路,路径密度至少$70\%$,**本题使用** `Special Judge`。 下面给出了标准广搜代码,读者可以**自行实验**(~也是C题的 std~): ```cpp line-numbers // C++14 (GCC 9) #include using namespace std; const int MAXN = 1e4 + 5; int n, u, sx, sy, ex, ey, dx[] {1, -1, 0, 0}, dy[] {0, 0, 1, -1}, ans; int f = 1, r = 1; char m[MAXN][MAXN]; bool vis[MAXN][MAXN]; struct node { int x, y, s; } o[MAXN * MAXN]; void bfs(int x, int y, int s) { f = 1, r = 1; node q = {x, y, s}; o[r] = q; vis[x][y] = 1; while (f = 1 && xx = 1 && yy > n; for (int i = 1; i m[i][j]; cin >> sx >> sy >>ex >> ey; bfs(sx, sy, 0); if (ans) cout > visited(N, vector < bool > (N, false)); stack < pair < int, int > > st; st.push({0, 1}); visited[0][1] = true; int count = 1; int dx[] {-1, 1, 0, 0}; int dy[] {0, 0, -1, 1}; bool found = false; while (!st.empty()) { int x = st.top().first; int y = st.top().second; st.pop(); if (x == N-1 && y == N-1) { found = true; break; } for (int d = 3; d >= 0; d--) { int nx = x + dx[d]; int ny = y + dy[d]; if (nx < 0 || nx >= N || ny < 0 || ny >= N || maze[nx][ny] == '#' || visited[nx][ny]) continue; visited[nx][ny] = true; ++ count; st.push({nx, ny}); } } if (!found) quitf(_wa, "Cannot reach the destination."); else { if (count > required) quitf(_ok, "Your answer is correct, visited %d cells.", count); else { double ans = double(count) / double((required * 1.0)); quitp(ans, "Visited only %d cells, which is not more than %d, which not accomplished the tasks the question asks.", count, required); } } } ```