hdu5433 Xiao Ming climbing(BestCoder Round #55 ($) )
来源:互联网 发布:淘宝人像摄影教程 编辑:程序博客网 时间:2024/04/30 06:12
Xiao Ming climbing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 489 Accepted Submission(s): 120
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 ($)
题意:给你一个图,求起点到终点花费的最小体力,体力的计算公式为(abs(H1−H2))/k,k为当前斗志,每走一步,斗志减1.
分析:普通的bfs,只是注意每一个点可能多次遍历,要找到该点花费最小的体力,最后在这些点内找出最终结果(详解见代码)。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<math.h>#include<algorithm>#include<queue>#include<set>#include<bitset>#include<map>#include<vector>#include<stdlib.h>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;#define ll long long#define CL(a) memset(a,0,sizeof(a))int n,m,k;int a,b,c,d;double minx;char ch[55];int mat[55][55];double vis[55][55][55];//vis[i][j][k]表示在(i,j)这个坐标的时候所剩k斗志的体力值int dir[4][2]={{0,-1},{0,1},{-1,0},{1,0}};struct node{ int x,y,t;//t为斗志 double ans;//体力}s[100005];void bfs(node st){ queue<node> q; node now, next; st.t=k; st.ans=0.0; vis[st.x][st.y][st.t]=0; q.push(st); while (!q.empty()) { now = q.front(); if (now.t<=0) return ; for (int i=0; i<4; i++)//平常的bfs { next.x = now.x+dir[i][0]; next.y = now.y+dir[i][1]; if (next.x<0||next.x>=n||next.y<0||next.y>=m) continue; if (mat[next.x][next.y]==-1) continue; next.ans = now.ans+(double)abs(mat[now.x][now.y]-mat[next.x][next.y])/(double)now.t; next.t = now.t-1; if (vis[next.x][next.y][next.t]-next.ans>0)//当前的得到的体力值比之前得到的体力值小 { vis[next.x][next.y][next.t]=next.ans;//更新 q.push(next);//入队 } } q.pop(); } return ;}int main (){ int T; scanf ("%d",&T); while (T--) { scanf ("%d%d%d",&n,&m,&k); for (int i=0; i<n; i++) { scanf ("%s",ch); for (int j=0; j<m; j++) { if (ch[j] == '#') mat[i][j] = -1; else mat[i][j] = ch[j]-'0'; } } scanf ("%d%d",&a,&b); scanf ("%d%d",&c,&d); if(k<=0) { printf("No Answer\n"); continue; } a--,b--,c--,d--; node st; st.x=a;st.y=b; //CL(vis); for (int i=0; i<=n; i++)//初始化 for (int j=0; j<=m; j++) for (int r=0; r<=k; r++) vis[i][j][r]=INF; bfs(st); minx=vis[c][d][1]; for (int i=1; i<=k; i++)//最后扫一遍,得到最小体力 minx=min(minx, vis[c][d][i]); if (minx-INF<0) printf ("%.2lf\n",minx); else printf ("No Answer\n"); } return 0;}
0 0
- hdu5433 Xiao Ming climbing(BestCoder Round #55 ($) )
- hdu5433 Xiao Ming climbing
- dp hdu5433 Xiao Ming climbing
- HDU 5433 Xiao Ming climbing(BFS)
- HDU 5433 Xiao Ming climbing
- HDU 5433 Xiao Ming climbing
- hdu 5433 Xiao Ming climbing(最短路)
- HDU 5433 Xiao Ming climbing(bfs+记忆化搜索)
- hdu 5433 Xiao Ming climbing (BFS+dp)
- hdu 5433 Xiao Ming climbing(优先队列+BFS)
- HDU - bc - Xiao Ming climbing (优先队列)
- hduacm 5433 Xiao Ming climbing题解
- hdu 5433 Xiao Ming climbing bfs
- HDU 5433(Xiao Ming climbing)(费用最短路:BFS+优先队列)
- HDOJ 5433 Xiao Ming climbing (BFS+三维标记)
- hdu(4349) Xiao Ming's Hope
- Xiao Ming's Hope
- Xiao Ming's Hope
- C++数据结构之List--线性实现
- Unity Web Player修改加载页面的LOGO
- 通过继承封装导航栏,使导航栏上面出现的按钮和图标均相同
- 数据仓库之ETL应用
- grunt使用笔记
- hdu5433 Xiao Ming climbing(BestCoder Round #55 ($) )
- iOS正则表达式使用
- 签证之家
- php向数据库中插入中文乱码问题
- HDU 5439 Aggregated Counting
- 利用Aspose.Words打印word文档
- Opencv+Kinect2.0获取景深图
- POJ 1401&&NYOJ 954 N!
- hdu 5438 Ponds(并查集+拓扑序)