hdu2653 Waiting ten thousand years for Love
2012-02-13 15:10
295 查看
题意:还是类似迷宫问题,已知起点和终点,在规定时间内求出到达终点的最少时间。
有俩种行走方式
1)飞行:
除了遇到‘#’ 以外,任何地方都能穿过,但需要消耗1s,同时消耗1 魔法值
注意:理论上遇到一个‘@’要消耗俩点魔法值,因为离开这个‘@’ 要消耗2点魔法值
2)行走:
有俩种情况不能走,1,遇到‘#’;2当前点是‘@’ 或者遇到的点是‘@’
View Code
有俩种行走方式
1)飞行:
除了遇到‘#’ 以外,任何地方都能穿过,但需要消耗1s,同时消耗1 魔法值
注意:理论上遇到一个‘@’要消耗俩点魔法值,因为离开这个‘@’ 要消耗2点魔法值
2)行走:
有俩种情况不能走,1,遇到‘#’;2当前点是‘@’ 或者遇到的点是‘@’
View Code
#include<iostream> #include<algorithm> #include<queue> using namespace std; char g[100][100]; bool vis[88][88][88]; int n,m,p,t,si,sj,ans; int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; struct node { int step,p,x,y; node(int a=0,int b=0,int c=0,int d=0):x(a),y(b),p(c),step(d){} bool friend operator <(const node a,const node b) { return a.step>b.step; } }; void BFS() { priority_queue<node> Q; node f=node(si,sj,p,0); Q.push(f); memset(vis,false,sizeof(vis)); vis[si][sj][p]=true; node temp; while(!Q.empty()) { temp=Q.top(); Q.pop(); if(temp.step>t) return ; if(g[temp.x][temp.y]=='L') { ans=temp.step; return ; } for(int k=0;k<4;k++) { int i=dir[k][0]+temp.x; int j=dir[k][1]+temp.y; if(i<0||i>n-1 || j<0 || j>m-1||g[i][j]=='#') continue; if(temp.p!=0 && !vis[i][j][temp.p-1]) { vis[i][j][temp.p-1]=true; Q.push(node(i,j,temp.p-1,temp.step+1)); } if(g[temp.x][temp.y]!='@' && g[i][j]!='@'&&!vis[i][j][temp.p]) { vis[i][j][temp.p]=true; Q.push(node(i,j,temp.p,temp.step+2)); } } } return ; } int main() { int cas=0; while(scanf("%d %d %d %d",&n,&m,&t,&p)==4) { for(int i=0;i<n;i++) { scanf("%s",g[i]); for(int j=0;j<m;j++) if(g[i][j]=='Y') si=i,sj=j; } ans=100001; BFS(); printf("Case %d:\n",++cas); if(ans>t) printf("Poor Yifenfei, he has to wait another ten thousand years.\n"); else printf("Yes, Yifenfei will kill Lemon at %d sec.\n",ans); } return 0; }
相关文章推荐
- HDU 2653 Waiting ten thousand years for Love
- HDU 2653 Waiting ten thousand years for Love
- Hdu 2579 Dating with girls(2) && hdu 2653 Waiting ten thousand years for Love【Bfs】
- 4.2.7 Waiting ten thousand years for Love
- hdu Waiting ten thousand years for Love
- HDU 2653 Waiting ten thousand years for Love
- hdoj 2653 Waiting ten thousand years for Love(优先队列+BFS)
- HDU 2653 - Waiting ten thousand years for Love
- HDU 2653 Waiting ten thousand years for Love
- hdoj 2653 - Waiting ten thousand years for Love
- HDU 2653 Waiting ten thousand years for Love(bfs+优先队列)
- 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
- learn English for ten years but still can not learn! Suggest you:then don't study(1)
- learn English for ten years but still can not learn! Suggest you:then don't study(2)
- Tim Cook tells employees Apple has ‘big plans’ for 2014 that ‘customers are going to love’
- The Plan for Future two years
- eclipse运行程序显示the user operation is waiting for "building workspace" to complete