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. python高级编程:缓存

    # -*- coding: utf-8 -*-__author__ = 'Administrator'#缓存"""对于运行代价很高的函数和方法结果,可以进行缓存,只要:1 ...

  2. Spring Ldap 的增删改查

    package ldap.entity; /** * 本测试类person对象来自schema文件的core.schema文件 * objectClass为person,必填属性和可选属性也是根据该对 ...

  3. Hibernate的查询 HQL查询 查询某几列

    HQL 是Hibernate Query Language的简写,即 hibernate 查询语言:HQL采用面向对象的查询方式.HQL查询提供了更加丰富的和灵活的查询特性,因此Hibernate将H ...

  4. android 银行卡。。空格输入

    class myWatcher implements TextWatcher { int beforeTextLength = 0; int onTextLength = 0; boolean isC ...

  5. python进阶之路4.1---生成器与迭代器

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  6. C#窗体实现文件拖拽功能

    1.首先要把你的窗体或者空间的AllowDrag属性设置为允许 2.注册DragEnter事件 3.获得文件路径,先通过e.Data.GetFormats()方法获得所有数据格式 4.调用e.GetD ...

  7. PowerDesigner与UML建模应用

    一.   PD简介 PowerDesigner 是一个集所有现代建模技术于一身的完整工具,它集成了强有力的业务建模技术.传统的数据库分析和实现,以及UML对象建模.通过了元数据的管理.冲突分析和真正的 ...

  8. VC进程提权

    如果我们想读取目标进程中的内存 就需要将进程提权 否则访问失败. 下面是提权代码 #include <TlHelp32.h> /****************************** ...

  9. OpenGL ES 2.0 限定符

    限定符 说明 作用 attribute 一般用于各个顶点各不相同的量,如顶点位置.颜色等 属性限定符,修饰的变量用来接收渲染管线传递进顶点着色器的当前顶点的各种属性值. 只能用来修饰符点数标量,浮点数 ...

  10. Longest Palindromic Substring -LeetCode

    题目 Given a string s,find the longest palindromic substring in S.You may assume  that the maximum len ...