hdu2433Xiao Ming climbing
来源:互联网 发布:淘宝新店采集器 编辑:程序博客网 时间:2024/06/09 19:36
Xiao Ming climbing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 593 Accepted Submission(s): 155
Problem Description
Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can hardly escape.
This mountain is pretty strange that its underside is a rectangle which size isn∗m and every little part has a special coordinate(x,y) and a height H .
In order to escape from this mountain,Ming needs to find out the devil and beat it to clean up the curse.
At the biginning Xiao Ming has a fighting willk ,if it turned to 0 Xiao Ming won't be able to fight with the devil,that means failure.
Ming can go to next position(N,E,S,W) from his current position that time every step,(abs(H1−H2))/k 's physical power is spent,and then it cost 1 point of will.
Because of the devil's strong,Ming has to find a way cost least physical power to defeat the devil.
Can you help Xiao Ming to calculate the least physical power he need to consume.
This mountain is pretty strange that its underside is a rectangle which size is
In order to escape from this mountain,Ming needs to find out the devil and beat it to clean up the curse.
At the biginning Xiao Ming has a fighting will
Ming can go to next position
Because of the devil's strong,Ming has to find a way cost least physical power to defeat the devil.
Can you help Xiao Ming to calculate the least physical power he need to consume.
Input
The first line of the input is a single integer T(T≤10) , indicating the number of testcases.
ThenT testcases follow.
The first line contains three integersn,m,k ,meaning as in the title(1≤n,m≤50,0≤k≤50) .
Then theN × M matrix follows.
In matrix , the integerH meaning the height of (i,j) ,and '#' meaning barrier (Xiao Ming can't come to this) .
Then follow two lines,meaning Xiao Ming's coordinate(x1,y1) and the devil's coordinate(x2,y2) ,coordinates is not a barrier.
Then
The first line contains three integers
Then the
In matrix , the integer
Then follow two lines,meaning Xiao Ming's coordinate
Output
For each testcase print a line ,if Xiao Ming can beat devil print the least physical power he need to consume,or output "NoAnswer " otherwise.
(The result should be rounded to 2 decimal places)
(The result should be rounded to 2 decimal places)
Sample Input
34 4 521342#232#2222211 13 34 4 721342#232#2222211 13 34 4 502#342#232#222#211 13 3
Sample Output
1.030.00No Answer
Source
BestCoder Round #55 ($)
只需要暴力BFS,去能到达终点的消耗的体力最小的
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define inf -0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mem0(a) memset(a,0,sizeof(a))#define mem1(a) memset(a,-1,sizeof(a))#define mem(a, b) memset(a, b, sizeof(a))typedef long long ll;int n,m,k;char s[51][51];double cost[51][51];int dis[51][51];int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};int si,sj,ei,ej;double ans;int flag;struct node{ int x,y,energy; double k;};void bfs(){ for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ cost[i][j]=9999999; } ans=999999999; flag=0; cost[si][sj]=0; queue<node>Q; node b; b.x=si; b.y=sj; b.k=0; b.energy=k; Q.push(b); while(!Q.empty()){ node a=Q.front(); Q.pop(); if(a.x==ei&&a.y==ej&&a.energy>=1){ if(a.k<ans){ ans=a.k; flag=1; } continue; } for(int k=0;k<4;k++){ int di=a.x+dir[k][0]; int dj=a.y+dir[k][1]; if(di<=0||dj<=0||di>n||dj>m||s[di][dj]=='#') continue; int z=abs(s[a.x][a.y]-s[di][dj]); double x=a.k+(double)z/(double)a.energy; if(x>=cost[di][dj]||a.energy<=1){ continue; } cost[di][dj]=x; b.x=di; b.y=dj; b.k=x; b.energy=a.energy-1; Q.push(b); } }}int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++){ scanf("%s",s[i]+1); } scanf("%d%d%d%d",&si,&sj,&ei,&ej); if(abs(ej-sj)+abs(ei-si)>=k){ printf("No Answer\n"); continue; } bfs(); if(flag==1) printf("%.2lf\n",ans); else{ printf("No Answer\n"); } } return 0;}
0 0
- hdu2433Xiao Ming climbing
- hdu5433 Xiao Ming climbing
- HDU 5433 Xiao Ming climbing
- dp hdu5433 Xiao Ming climbing
- HDU 5433 Xiao Ming climbing
- HDU - bc - Xiao Ming climbing (优先队列)
- hduacm 5433 Xiao Ming climbing题解
- hdu 5433 Xiao Ming climbing bfs
- HDU 5433 Xiao Ming climbing(BFS)
- hdu 5433 Xiao Ming climbing(最短路)
- hdu5433 Xiao Ming climbing(BestCoder Round #55 ($) )
- HDU 5433 Xiao Ming climbing(bfs+记忆化搜索)
- hdu 5433 Xiao Ming climbing (BFS+dp)
- hdu 5433 Xiao Ming climbing(优先队列+BFS)
- HDOJ 5433 Xiao Ming climbing (BFS+三维标记)
- HDU 5433(Xiao Ming climbing)(费用最短路:BFS+优先队列)
- Zhu Ming
- Ming YANG
- 第二周实践项目(2)~程序的多文件组织
- 【matlab】matlab文件操作fopen,fseek,fread,fclose等
- iOS进阶----block的使用
- TS流的解析
- 项目2 - 建设“顺序表”算法库
- hdu2433Xiao Ming climbing
- Wireshark使用方法(学习笔记二——查询统计) http://www.2cto.com/Article/201201/115880.html
- MVC图片验证
- hibernate的uuid主键生成器(使用注解)
- StringBuffer和String的优缺点比较
- 第二周实践项目3-体验复杂度(2)汉诺塔
- hdu5442 Favorite Donut(最大表示法+KMP)
- POJ 3069 Saruman's Army (贪心 )
- 2015-9-14 项目1- 顺序表的基本运算