正文
增加 5 行删除 5 行
6 行未改动78910111213141528 行未改动444546474849505152123 行未改动全部展开17617717817918018118218318417 行未改动202203204205206207208209210211212213214215216217218219220156 行未改动全部展开6 行未改动### 这题就是个典型的多源 BFS 网格扩散题:先把第一天所有已经得病的人都找出来,一起扔进队列里,用 BFS 一层一层往外扩大,每个格子被感染的天数记在数组里,最后只要数一下,在第 m 天之内被感染的、不是空房间的格子,加起来输出即可。## **100pts**```#include<bits/stdc++.h>using namespace std;const int N=1e2+5;int n,vis[N][N],ans,m;int dx[5]={0,0,-1,1};int dy[5]={-1,1,0,0};28 行未改动vis[nx][ny]=vis[now.x][now.y]+1;q.push({nx,ny});}}}int main(){cin>>n;for(int i=1;i<=n;i++)123 行未改动全部展开int d[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};void solve() {vector<vector<int>> tmp(n+5, vector<int> (m+5, 0));q = tmp;vis = tmp;while (qq.size()) qq.pop();q[ex][ey] = 1;17 行未改动for (int i=0; i<4; i++) {int nx = now.x+d[i][0], ny = now.y+d[i][1];if (nx < 1 or nx > n or ny < 1 or ny > m) continue;if (vis[nx][ny] or mp[nx][ny] == 'X') continue;qq.push({nx, ny, now.st+1});vis[nx][ny] = 1;}}cout << "Poor Harry\n";}signed main() {cin >> n >> m;mp.resize(n+5, vector<char>(m+5));for (int i=1; i<=n; i++)for (int j=1; j<=m; j++)cin >> mp[i][j];while (cin >> ex >> ey >> sx >> sy) {156 行未改动全部展开6 行未改动78910111213141528 行未改动444546474849505152123 行未改动全部展开17617717817918018118218318417 行未改动202203204205206207208209210211212213214215216217218219220156 行未改动全部展开6 行未改动### 这题就是个典型的多源 BFS 网格扩散题:先把第一天所有已经得病的人都找出来,一起扔进队列里,用 BFS 一层一层往外扩大,每个格子被感染的天数记在数组里,最后只要数一下,在第 m 天之内被感染的、不是空房间的格子,加起来输出即可。## **100pts**```#include<bits/stdc++.h>using namespace std;const int N=1e2+5;int n,vis[N][N],ans,m;int dx[5]={0,0,-1,1};int dy[5]={-1,1,0,0};28 行未改动vis[nx][ny]=vis[now.x][now.y]+1;q.push({nx,ny});}}}int main(){cin>>n;for(int i=1;i<=n;i++)123 行未改动全部展开int d[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};void solve() {vector<vector<int>> tmp(n+5, vector<int> (m+5, 0));q = tmp;vis = tmp;while (qq.size()) qq.pop();q[ex][ey] = 1;17 行未改动for (int i=0; i<4; i++) {int nx = now.x+d[i][0], ny = now.y+d[i][1];if (nx < 1 or nx > n or ny < 1 or ny > m) continue;if (vis[nx][ny] or mp[nx][ny] == 'X') continue;qq.push({nx, ny, now.st+1});vis[nx][ny] = 1;}}cout << "Poor Harry\n";}signed main() {cin >> n >> m;mp.resize(n+5, vector<char>(m+5));for (int i=1; i<=n; i++)for (int j=1; j<=m; j++)cin >> mp[i][j];while (cin >> ex >> ey >> sx >> sy) {156 行未改动全部展开