HDU-1180 诡异的楼梯
来源:互联网 发布:阿里云国际版账号注册 编辑:程序博客网 时间:2024/05/12 16:31
http://acm.hdu.edu.cn/showproblem.php?pid=1180
迷宫 就多了个楼梯的问题 可以停在原点 楼梯是瞬间通过
#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<vector>#include<queue>#include<algorithm>using namespace std;const int maxn = 25;const int inf = 1<<30;int n,m;char map[maxn][maxn];int xs[] = {0,1,0,-1};int ys[] = {1,0,-1,0};struct node{int x,y;int g;bool operator < ( const node &k ) const{return g > k.g;}};int BFS( int sx,int sy ){node cur,cnt;priority_queue<node>que;cur.x = sx; cur.y = sy;cur.g = 0;que.push(cur);while( !que.empty() ){cur = que.top();que.pop();for( int i = 0; i < 4; i ++ ){cnt.x = cur.x + xs[i];cnt.y = cur.y + ys[i];if( cnt.x >= 1 && cnt.x <= n && cnt.y >= 1 && cnt.y <= m && map[cnt.x][cnt.y] != '*' ){if( map[cnt.x][cnt.y] == 'T' )return cur.g + 1;else if( map[cnt.x][cnt.y] == '|' ){if( cur.g %2 && (i == 0 || i == 2) )cnt.g = cur.g + 1;else if( !(cur.g%2) && ( i == 1 || i == 3 ) )cnt.g = cur.g + 1;elsecnt.g = cur.g + 2;cnt.x = cnt.x + xs[i];cnt.y = cnt.y + ys[i];if( map[cnt.x][cnt.y] == 'T' )return cnt.g;que.push(cnt);}else if( map[cnt.x][cnt.y] == '-' ){if( !(cur.g %2) && (i == 0 || i == 2) )cnt.g = cur.g + 1;else if( cur.g%2 && ( i == 1 || i == 3 ) )cnt.g = cur.g + 1;elsecnt.g = cur.g + 2;cnt.x = cnt.x + xs[i];cnt.y = cnt.y + ys[i];if( map[cnt.x][cnt.y] == 'T' )return cnt.g;que.push(cnt);}else{cnt.g = cur.g + 1;que.push(cnt);map[cnt.x][cnt.y] = '*';}}}}return -1;}int main(){//freopen("data.txt","r",stdin);int sx,sy;while( scanf("%d%d",&n,&m) == 2 ){for( int i = 1; i <= n; i ++ ){getchar();for( int j = 1; j <= m; j ++ ){scanf("%c",&map[i][j]);if( map[i][j] == 'S' ){sx = i; sy = j;}}}int ans = BFS( sx,sy );if( ans != -1 )printf("%d\n",ans);}return 0;}
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- Hdu-1180(诡异的楼梯)
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- 诡异的楼梯 hdu 1180
- HDU-1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180诡异的楼梯
- HDU 1180诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- 字符集校对规则collation
- Apache自动添加地址末尾的斜线
- IOS block编程注意事项
- JS实现JSP页面,鼠标禁止另存,复制,右键,选取
- python代码统计大文本文件行数
- HDU-1180 诡异的楼梯
- 北大ACM 1007题 感觉本人写的代码还可以 和大家分享下
- JAVA代码片段--获取当前是星期几
- unix基础篇
- Cocos2dx: 弹出对话框的设计与实现
- 设计模式总结
- 迭代器的删除问题
- jsp 按照数据规则输出类似合并单元格类型的数据
- j2se之方法的封装