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 is n∗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 will k,if it turned to  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.
Input
The first line of the input is a single integer T(T≤), indicating the number of testcases. 

Then T testcases follow.

The first line contains three integers n,m,k ,meaning as in the title(≤n,m≤,≤k≤).

Then the N × M matrix follows.

In matrix , the integer H 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.
 
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  decimal places)
 
Sample Input
 


#
# #
# #
#
#
#
Sample Output
1.03
0.00
No Answer
 
Source
 
三维数组标记消耗的体力,如果if(vis[t2.x][t2.y][t2.t]>t2.v) 则继续入队。
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#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;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 56
#define inf 1e12
int n,m,k;
char mp[N][N];
int sgn(double e)
{
if(fabs(e)<eps)return ;
return e>?:-;
}
struct Node{
int x,y;
int t;
double v;
}st,ed;
double vis[N][N][N];
int M[N][N];
int dirx[]={,,-,};
int diry[]={,,,-};
void bfs(){
queue<Node>q;
st.v=;
q.push(st);
Node t1,t2;
vis[st.x][st.y][st.t]=;
while(!q.empty()){
t1=q.front();
q.pop();
if(t1.t<=) continue;
for(int i=;i<;i++){
t2=t1;
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
if(t2.x< || t2.x>=n || t2.y< || t2.y>=m) continue;
if(M[t2.x][t2.y] == -) continue; int num1=M[t2.x][t2.y];
int num2=M[t1.x][t1.y];
t2.v+=(abs(num1-num2)*1.0)/(t2.t);
t2.t--;
if(sgn(vis[t2.x][t2.y][t2.t]-t2.v)>){
vis[t2.x][t2.y][t2.t]=t2.v;
q.push(t2);
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
scanf("%s",mp[i]);
for(int j=; j<m; j++)
if(mp[i][j]=='#')M[i][j]=-;
else M[i][j]=mp[i][j]-'';
} scanf("%d%d%d%d",&st.x,&st.y,&ed.x,&ed.y);
if(k<=){
printf("No Answer\n"); continue;
}
st.x--;
st.y--;
ed.x--;
ed.y--;
st.t=k;
st.v=;
//memset(vis,inf,sizeof(vis));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
for(int r=;r<=k;r++){
vis[i][j][r]=inf;
}
}
}
bfs();
double ans=vis[ed.x][ed.y][];
for(int i=;i<=k; i++)
ans=min(ans,vis[ed.x][ed.y][i]); if(sgn(ans-inf)>=){
printf("No Answer\n");
}
else{
printf("%.2lf\n",ans);
}
}
return ;
}

hdu 5433 Xiao Ming climbing(bfs+三维标记)的更多相关文章

  1. HDu 5433 Xiao Ming climbing (BFS)

    题意:小明因为受到大魔王的诅咒,被困到了一座荒无人烟的山上并无法脱离.这座山很奇怪: 这座山的底面是矩形的,而且矩形的每一小块都有一个特定的坐标(x,y)和一个高度H. 为了逃离这座山,小明必须找到大 ...

  2. HDU 5433 Xiao Ming climbing 动态规划

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...

  3. HDU 5433 Xiao Ming climbing dp

    Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...

  4. HDU 5433 Xiao Ming climbing

    题意:给一张地图,给出起点和终点,每移动一步消耗体力abs(h1 - h2) / k的体力,k为当前斗志,然后消耗1斗志,要求到终点时斗志大于0,最少消耗多少体力. 解法:bfs.可以直接bfs,用d ...

  5. HDU 4349 Xiao Ming's Hope 找规律

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/ ...

  6. hdu5433 Xiao Ming climbing

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  7. HDU 4349 Xiao Ming's Hope lucas定理

    Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting nu ...

  8. hdu 4349 Xiao Ming's Hope 规律

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. HDU 4349——Xiao Ming's Hope——————【Lucas定理】

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. poj 2407 Relatives(简单欧拉函数)

    Description Given n, a positive integer, how many positive integers less than n are relatively prime ...

  2. (转)iOS Wow体验 - 第五章 - 利用iOS技术特性打造最佳体验

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第五章译文精选,其余章节将陆续放出.上一篇:Wow ...

  3. jQuery的ajax jsonp跨域请求

    了解:ajax.json.jsonp.“跨域”的关系 要弄清楚以上ajax.json.jsonp概念的关系,我觉得弄清楚ajax是“干什么的”,“怎么实现的”,“有什么问题”,“如果解决存在的问题”等 ...

  4. MongoDB分片技术[转]

    8天学通MongoDB——第六天 分片技术   在mongodb里面存在另一种集群,就是分片技术,跟sql server的表分区类似,我们知道当数据量达到T级别的时候,我们的磁盘,内存 就吃不消了,针 ...

  5. 【技术文档】《算法设计与分析导论》R.C.T.Lee等·第7章 动态规划

    由于种种原因(看这一章间隔的时间太长,弄不清动态规划.分治.递归是什么关系),导致这章内容看了三遍才基本看懂动态规划是什么.动态规划适合解决可分阶段的组合优化问题,但它又不同于贪心算法,动态规划所解决 ...

  6. Jquery:强大的选择器<二>

    今天跟着资料做了一个示例,为什么我感觉自己做的没书上的好看呢?好吧,我承认自己对css样式只懂一点皮毛,我也不准备深度的去学习它,因为……公司有美工嘛! 这个小示例只是实现了元素的隐藏和显示.元素cl ...

  7. Android开发环境的搭建之(一)Java开发环境的安装

    (1)  安装JDK(Java Developer Kit).下载JDK1.8并安装jdk-8u60-windows-i586.exe.下载官方链接http://www.oracle.com/tech ...

  8. 全世界最详细的图形化VMware中linux环境下oracle安装(三)【weber出品必属精品】

    数据库软件和数据库都建好了,基本上可以说完成90%的工作,但是美中不足的就是企业管理器还没有安装好,现在我们就开始安装企业管理器吧. 安装之前我们先将补丁给补上.补丁我们也是采用禁默安装.补丁:p83 ...

  9. keydown和keypress

    常见的键盘事件是keyup和keydown.淡蓝就经常用 document.onkeyup = function (e) { if ((e.keyCode || e.which) === 13) // ...

  10. C/C++中的成员函数指针声明及使用

    代码: #include <iostream> using namespace std; class Test{ public: void func(){ cout<<&quo ...