hdu1180 诡异的楼梯 --bfs+优先级队列
来源:互联网 发布:一手车主数据论坛 编辑:程序博客网 时间:2024/06/09 19:06
遇到楼梯特殊处理
#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int x, y, t; node() {} node(int xx, int yy, int tt):x(xx), y(yy), t(tt) {} friend bool operator<(const node &a, const node &b) { return a.t > b.t; }};char mp[50][50];bool vis[50][50];int nx[] = {-1, 0, 1, 0};int ny[] = {0, 1, 0, -1};int bfs(int m, int n, int sx, int sy) { memset(vis, false, sizeof(vis)); priority_queue<node> q; vis[sx][sy] = true; q.push(node(sx, sy, 0)); while (!q.empty()) { node t = q.top(); q.pop(); if (mp[t.x][t.y] == 'T') return t.t; for (int i = 0; i < 4; i++) { int tx = t.x + nx[i]; int ty = t.y + ny[i]; int tt = t.t + 1; if (tx < 1 || tx > m || ty < 1 || ty > n || vis[tx][ty] || mp[tx][ty] == '*') continue; if(mp[tx][ty] == '|' || mp[tx][ty] == '-') { if (mp[tx][ty] == '|') { if ((i == 0 || i == 2) && t.t%2 || (i == 1 || i == 3) && t.t%2==0) tt++; } else if (mp[tx][ty] == '-') { if ((i == 0 || i == 2) && t.t%2==0 || (i == 1 || i == 3) && t.t%2) tt++; } tx += nx[i]; ty += ny[i]; if (tx < 1 || tx > m || ty < 1 || ty > n || vis[tx][ty] || mp[tx][ty] == '*') continue; } q.push(node(tx, ty, tt)); vis[tx][ty] = true; } } return -1;}int main() { //freopen("in", "r", stdin); int m, n; while(~scanf("%d%d", &m, &n)) { int sx, sy; getchar(); for (int i = 1; i <= m; i++) fgets(mp[i]+1, 50, stdin); for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) if (mp[i][j] == 'S') { sx = i; sy = j; break; } printf("%d\n", bfs(m, n, sx, sy)); } return 0;}
0 0
- hdu1180 诡异的楼梯 --bfs+优先级队列
- hdu1180诡异的楼梯(BFS+优先队列)
- hdu1180-诡异的楼梯(bfs+优先队列)
- HDU1180 诡异的楼梯--BFS
- hdu1180诡异的楼梯 bfs
- hdu1180诡异的楼梯(bfs)
- hdu1180 诡异的楼梯--BFS
- HDU1180-诡异的楼梯(bfs)
- HDU1180 诡异的楼梯(BFS)
- HDU1180——诡异的楼梯(BFS+优先队列)
- hdu1180 诡异的楼梯(BFS+优先队列)
- hdu1180 诡异的楼梯(优先队列bfs)
- HDU1180 诡异的楼梯(广搜BFS+优先队列)
- hdu1180——诡异的楼梯(优先队列+bfs)
- 【搜索-BFS】HDU1180诡异的楼梯
- hdu1180诡异的楼梯(bfs)
- hdu1180 诡异的楼梯
- HDU1180 诡异的楼梯
- distinct去掉mysql中重复值
- C++继承中的内存布局
- (3)Session 和 Cookie
- 视频压缩资料摘录
- 实现字符串翻转(逆序输出)
- hdu1180 诡异的楼梯 --bfs+优先级队列
- 关于警告[Accessibility] Missing contentDescription attribute on image的解决方法
- 4-1 Strongly Connected Components (17分)/PTA
- android6.0 SystemUI之快捷设置区域QSPanel及点击事件流程分析
- 深度解析Holograms 230: Spatial mapping 空间映射
- opencv处理图像对比度和亮度
- OSG 自带状态器修改方法
- ecshop重置后台密码
- 如果是我