HDU 2653 Waiting ten thousand years for Love
来源:互联网 发布:秒赞网阿里云监控教程 编辑:程序博客网 时间:2024/06/10 21:28
题目链接~~>
做题感悟:这题有点失败,没考虑到必须用三维标记,开始感觉用二维就可以的,但是后来看到别人用三维才考虑到这样有的点就遍历不到。
解题思路:BFS + 优先队列 :如果一个格子不是 @ 或者到达的格子也不为 @ 那么就可以走过去 | | 飞过去,剩下的情况必须飞过去。(如果两个@相连且你从其中一个到达另一个只需要一个magic power 就可以)。
代码:
#include<stdio.h>#include<iostream>#include<map>#include<stack>#include<string>#include<string.h>#include<stdlib.h>#include<math.h>#include<vector>#include<queue>#include<algorithm>using namespace std ;#define LEN sizeof(struct node)#define pret(a,b) memset(a,b,sizeof(a))#define lld __int64const double PI = 3.1415926 ;const double INF = 999999999 ;const double esp = 1e-4 ;const lld md= 2810778 ;const int MX = 85 ;int n,m,tx,kx ;char s[MX][MX] ;bool vis[MX][MX][MX] ;int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1} ;struct node{ int x,y,step,p ; friend bool operator < (const node &a,const node &b) // 优先队列 { return a.step > b.step ; }} ;bool search(int x,int y){ if(x<0||y<0||x>=n||y>=m||s[x][y]=='#') return false; return true ;}int bfs(int x,int y,int kx){ int sx,sy ; priority_queue<node>q ; node curt,next ; memset(vis,false,sizeof(vis)) ; curt.x=x ; curt.y=y ; curt.step=0 ; curt.p=kx ; vis[x][y][kx]=true ; q.push(curt) ; while(!q.empty()) { curt=q.top() ; q.pop() ; if(curt.step>tx) return -1 ; // 剪枝最少的时间都大于 tx so…… if(s[curt.x][curt.y]=='L') return curt.step ; for(int i=0 ;i<4 ;i++) { next.x=sx=curt.x+dx[i] ; next.y=sy=curt.y+dy[i] ; next.p=curt.p ; if(search(sx,sy)) { if(s[curt.x][curt.y]!='@'&&s[sx][sy]!='@'&&!vis[sx][sy][next.p]&&curt.step+2<=tx)// 走过去 { next.step=curt.step+2 ; vis[sx][sy][next.p]=true ; q.push(next) ; } if(next.p>0&&!vis[sx][sy][next.p-1]&&curt.step+1<=tx) // 飞过去 { next.p-- ; next.step=curt.step+1 ; vis[sx][sy][next.p]=true ; q.push(next) ; } } } } return -1 ;}int main(){ int sx,sy,q=1 ; while(~scanf("%d%d%d%d",&n,&m,&tx,&kx)) { for(int i=0 ;i<n ;i++) { scanf("%s",s[i]) ; for(int j=0 ;j<m ;j++) if(s[i][j]=='Y') { sx=i ; sy=j ; } } int mx=bfs(sx,sy,kx) ; printf("Case %d:\n",q++) ; if(mx!=-1) printf("Yes, Yifenfei will kill Lemon at %d sec.\n",mx) ; else printf("Poor Yifenfei, he has to wait another ten thousand years.\n") ; } return 0 ;}
0 0
- HDU 2653 Waiting ten thousand years for Love
- HDU 2653 Waiting ten thousand years for Love
- HDU 2653Waiting ten thousand years for Love
- Waiting ten thousand years for Love
- Hdu 2579 Dating with girls(2) && hdu 2653 Waiting ten thousand years for Love【Bfs】
- hdoj 2653 Waiting ten thousand years for Love(优先队列+BFS)
- HDU2653 Waiting ten thousand years for Love (三维广搜+优先队列)
- HDU 2619 - Love you Ten thousand years (数论)
- hdu 2619 Love you Ten thousand years(数论,待解决)
- The Star Zoo——5、Waiting for fifteen thousand years
- ten beautiful sentences for love
- Concurrent Ten Thousand Connections.
- A thousand years
- Ten years. One vision
- 十年,ten years
- The Recent Ten Years
- lessen ten years
- 十年 Ten years
- 高效开发 Android App 的 10 个建议
- Apache Hadoop 版本
- Eclipse开发环境搭建
- EnumSet的运用注意
- 23种设计模式(1):单例模式
- HDU 2653 Waiting ten thousand years for Love
- Android进阶2之 阴影制作(Shadow)
- Mono for Android——使用C#,在手机上运行
- 【CocoStudio游戏开发之三】使用Cocostudio UI编辑器篇
- 四门轿跑 标致发布Exalt概念车设计图
- android开发广播的使用Broadcast Receiver
- ios 引用处理导致的文件删除却提示未能找到该文件
- 让Activity变成一个窗口
- 使用CppSQLite3访问SQLite数据库