诡异的楼梯
来源:互联网 发布:大淘客cms网站 编辑:程序博客网 时间:2024/05/19 01:07
HDU1180:Link Hrer
#include <cstdio>#include <algorithm>#include <iostream>#include <queue>using namespace std;struct Point{ int x,y,step; friend bool operator < (const Point a,const Point b) { return a.step > b.step; }};int dir[5][3] = {{1,0},{0,1},{-1,0},{0,-1}};int n,m,s,e;char map[22][22];void Manage(){ for(int i = 0;i <= n+1; i++) { map[i][0] = '*'; map[i][m+1] = '*'; } for(int j = 0;j <= m+1; j++) { map[0][j] = '*'; map[n+1][j] = '*'; }}bool IsNeedPlus(Point temp,int i){ if(map[temp.x][temp.y] == '-'){ if(i % 2 == 0){ if(temp.step % 2 == 0) return false; else return true; }else { if(temp.step % 2 == 0) return true; else return false; } }else { if(i % 2 == 0){ if(temp.step % 2 == 0) return true; else return false; }else { if(temp.step % 2 == 0) return false; else return true; } }}void BFS(int u,int v){ priority_queue <Point>Q; Point temp,q; q.x= u; q.y = v; q.step = 0; Q.push(q); while(!Q.empty()) { q = Q.top(); Q.pop(); if(q.x == s&&q.y == e) { printf("%d\n",q.step); return ; } q.step ++; for(int i = 0;i < 4;i++) { temp.x = q.x + dir[i][0]; temp.y = q.y + dir[i][1]; temp.step = q.step; if(temp.x != '*') { if(map[temp.x][temp.y] == '.'||map[temp.x][temp.y] == 'T') { map[temp.x][temp.y] = '*'; Q.push(temp); }else if(map[temp.x][temp.y]=='|'||map[temp.x][temp.y]=='-') { if(!IsNeedPlus(temp,i)){ temp.x += dir[i][0]; temp.y += dir[i][1]; if(map[temp.x][temp.y] != '*') { map[temp.x][temp.y] = '*'; Q.push(temp); } }else { Q.push(q); } } } } }}int main(){ while(~scanf("%d%d",&n,&m)) { for(int i = 1;i <= n;i++) scanf("%s",map[i]+1); Manage(); int u,v; for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) { if(map[i][j] == 'S') { u = i; v = j; } if(map[i][j] == 'T') { s = i; e = j; } } BFS(u,v); } return 0;}
- hdu1180 诡异的楼梯
- BFS+诡异的楼梯
- 诡异的楼梯
- 诡异的楼梯
- HDU1180 诡异的楼梯
- hdu1180 诡异的楼梯
- hdu1180诡异的楼梯
- hdu 诡异的楼梯
- 诡异的楼梯
- HDU1180 诡异的楼梯
- hdoj1180 诡异的楼梯
- 诡异的楼梯
- HDU:诡异的楼梯
- hdu 诡异的楼梯
- 诡异的楼梯
- HDU1180-诡异的楼梯
- 诡异的楼梯
- 诡异的楼梯 HDU
- LPTSTR CString 相互转换 CString char * 相互转换
- 新形势下的烟草商业数据中心建设
- printk内核调试
- Python语言选择分支语句和小数位控制输出
- C++拷贝构造函数被调用的三种情况
- 诡异的楼梯
- Qt mysql驱动编译
- [RHCE training] 2nd day
- 写博客
- 设计网站
- 浏览器渲染原理简介
- 在Eclipse中使用JUnit4进行单元测试
- iOS UI素材 iPhone UI素材 psd文件下载
- 产品经理用到的工具都有哪些?