5 条题解
-
0
名副其实的广搜题,
但是我仍然不会废话不多说,直接上代码#include <iostream> #include <queue> using namespace std; int r, c, x, y; int dir[8][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; char ma[105][105]; bool vis[105][105]; int ans = 0; struct node{ int x, y, s; }; queue<node > q; void bfs(int x, int y){ vis[x][y] = 1; q.push((node){x, y, 0}); while(!q.empty()){ node p = q.front(); q.pop(); ans = max(ans, p.s); for(int i=0; i<8; i++){ int nx = p.x + dir[i][0]; int ny = p.y + dir[i][1]; if(1 <= nx && nx <= r && 1 <= ny && ny <= c){ if(vis[nx][ny] == 0 && ma[nx][ny] != '*'){ vis[nx][ny] = 1; q.push((node){nx, ny, p.s + 1}); } } } } } int main(){ cin>>c>>r>>x>>y; for(int i=1; i<=r; i++){ for(int j=1; j<=c; j++){ cin>>ma[i][j]; } } bfs(r - y + 1, x); cout<<ans<<endl; }
信息
- ID
- 100
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 690
- 已通过
- 148
- 上传者