dhu 1180 诡异的楼梯
来源:互联网 发布:java split函数 编辑:程序博客网 时间:2024/06/06 01:26
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;char Map[25][25];int vist[25][25];int dir[][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};int n, m;struct node { int x, y; int time;};int sx, sy, ex, ey;int ans;bool judge(int a, int b) { if(a >= 1 && a <= n && b >= 1 && b <= m&& Map[a][b] != '*'&&vist[a][b] == 0) return true; return false;}void work(int sx, int sy) { memset(vist, 0, sizeof(vist)); queue<node>que; node cur, next; cur.x = sx; cur.y = sy; cur.time = 0; vist[sx][sy] = 1; que.push(cur); while(!que.empty()) { cur = que.front(); que.pop(); // printf("%d %d %d\n", cur.x, cur.y , cur.time); if(cur.x == ex && cur.y == ey) { ans = cur.time; return; } for(int i = 0; i < 4; i++) { int a = cur.x + dir[i][0]; int b = cur.y + dir[i][1]; if(judge(a, b)) { if(Map[a][b] == '|' || Map[a][b] == '-') { if(cur.time %2 == 0) { if((Map[a][b] == '|' && i < 2)||(Map[a][b] == '-'&&i > 1)) { a = a + dir[i][0]; b = b + dir[i][1]; }else { next = cur; next.time++; que.push(next); continue; } }else { if((Map[a][b] == '|' && i > 1)||(Map[a][b] == '-'&&i < 2)) { a = a + dir[i][0]; b = b + dir[i][1]; }else { next = cur; next.time++; que.push(next); continue; } } } if(judge(a, b)) { if(Map[a][b] == 'T') { ans = cur.time + 1; return ; } else if(Map[a][b] == '.'){ next.x = a; next.y = b; next.time = cur.time+1; vist[a][b] = 1; que.push(next); } } } } }}int main(){ while(scanf("%d%d", &n, &m) != EOF) { for(int i = 1; i <= n; i++) { scanf("%s", Map[i] + 1); for(int j = 1; j <= m; j++) { if(Map[i][j] == 'T') { ex = i; ey = j; } if(Map[i][j] == 'S') { sx = i; sy = j; } } } ans = 0; work(sx, sy); printf("%d\n", ans); } return 0;}
0 0
- dhu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- Hdu-1180(诡异的楼梯)
- HDOJ 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 诡异的楼梯
- poj 1947 Rebuilding Roads(树形dp)
- [Matlab][数据挖掘算法][线性回归]
- Linux下安装MySQL数据库以及用C语言编程存取数据库
- leetcode - Remove Duplicates from Sorted List
- 访问权限控制
- dhu 1180 诡异的楼梯
- Android应用中使用百度地图API并添加标注(一)
- 腾讯2014实习生笔试题(重庆站)
- MPI之自己实现Alltoall()函数
- PAT1003
- Linux Mint 16 petra升级到Mint 17 Qianna
- 我的ios开发笔记(1)tableview+nav
- HDU2220 Eddy's AC难题
- 基于ArcGIS Engine和C#的管线剖面图的制作