版本比较
题解:P15563 [CCPC 2025 哈尔滨站] 网格避障
正文
增加 8 行删除 8 行
1234567891011123 行未改动161718192021222324252627282930313233343520 行未改动56575859606162636424 行未改动8990919293949596977 行未改动给定一个含 k 个障碍的 n*m 网格图。要求统计所有 $2^k$ 种“通过障碍的上下方式”中,每种方式的最短路径。对于每个障碍:- 若只能从上方通过,则将该障碍正上方的格子全设为障碍;- 若只能从下方通过,则将该障碍正下方的格子全设为障碍。然后对每种情况跑一遍 BFS。时间复杂度 $O(nm$2^k$)$。虽是暴力,但实现简单、思路直观。————————————————3 行未改动#include <bits/stdc++.h>using namespace std;#define endl '\n'const int N = 1 << 9;const int inf = INT_MAX / 2;struct node {int x, y;} p[1 << 9];int a[N][N], dis[N][N], vis[N][N], n, m;int dx[4] = {1, -1, 0};int dy[4] = {0, 0, 1};int calc() {queue <node> q;for (int i = 1; i <= n; i++) {dis[i][1] = 0;20 行未改动}if (ans == inf) return -1;else return ans;}void solve() {cin >> n >> m;int k;cin >> k;24 行未改动cout << ans << " ";}cout << endl;}int main() {ios::sync_with_stdio(0); cin.tie(0);int T = 1;cin >> T;7 行未改动1234567891011123 行未改动161718192021222324252627282930313233343520 行未改动56575859606162636424 行未改动8990919293949596977 行未改动给定一个含 k 个障碍的 n*m 网格图。要求统计所有 $2^k$ 种“通过障碍的上下方式”中,每种方式的最短路径。对于每个障碍:- 若只能从上方通过,则将该障碍正上方的格子全设为障碍;- 若只能从下方通过,则将该障碍正下方的格子全设为障碍。然后对每种情况跑一遍 BFS。时间复杂度 $O(nm$2^k$)$。虽是暴力,但实现简单、思路直观。————————————————3 行未改动#include <bits/stdc++.h>using namespace std;#define endl '\n'const int N = 1 << 9;const int inf = INT_MAX / 2;struct node {int x, y;} p[1 << 9];int a[N][N], dis[N][N], vis[N][N], n, m;int dx[4] = {1, -1, 0};int dy[4] = {0, 0, 1};int calc() {queue <node> q;for (int i = 1; i <= n; i++) {dis[i][1] = 0;20 行未改动}if (ans == inf) return -1;else return ans;}void solve() {cin >> n >> m;int k;cin >> k;24 行未改动cout << ans << " ";}cout << endl;}int main() {ios::sync_with_stdio(0); cin.tie(0);int T = 1;cin >> T;7 行未改动