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

Total Submission(s): 438    Accepted Submission(s): 108


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 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.
 

Input
The first line of the input is a single integer T(T≤10),
indicating the number of testcases. 

Then T testcases
follow.

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

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 2 decimal places)
 

Sample Input

3
4 4 5
2134
2#23
2#22
2221
1 1
3 3
4 4 7
2134
2#23
2#22
2221
1 1
3 3
4 4 50
2#34
2#23
2#22
2#21
1 1
3 3
 

Sample Output

1.03
0.00

No Answer

这题用宽搜做,用minx[x][y][d]表示走到(x,y)且剩余斗志为d的最少体力,bfs的过程中,只有满足边界条件并且下一步算出来的值要小于min[xx][yy][d]时才把这个点放入队列。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 999999999
#define maxn 10050
char gra[55][55];
int vis[55][55];
int tab[10][2]={0,1,-1,0,0,-1,1,0};
int n,m,k,x3,x2,y3,y2;
struct node{
double tili;
int x,y,douzhi;
}q[1111111]; double minx[55][55][55]; void bfs()
{
int i,j,front,rear,x,y,xx,yy,douzhi,dou;
double tili,ti;
front=rear=1;
q[front].x=x3;q[front].y=y3;q[front].tili=0;q[front].douzhi=k;
while(front<=rear){
x=q[front].x;y=q[front].y;tili=q[front].tili;douzhi=q[front].douzhi;
front++;
//printf("%d %d %.2f %d\n",x,y,tili,douzhi);
if(x==x2 && y==y2){
continue;
}
for(i=0;i<4;i++){
xx=x+tab[i][0];yy=y+tab[i][1];
if(xx>=1 && xx<=n && yy>=1 && yy<=m && gra[xx][yy]!='#'){
ti=tili+fabs(gra[xx][yy]-gra[x][y])/(double)douzhi;
dou=douzhi-1;
if(dou==0 || ti>=minx[xx][yy][dou]){
continue;
}
minx[xx][yy][dou]=ti;
rear++;
q[rear].x=xx;q[rear].y=yy;q[rear].tili=ti;q[rear].douzhi=dou;
} } }
} int main()
{
int i,j,T,h;
double ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=n;i++){
scanf("%s",gra[i]+1);
}
scanf("%d%d%d%d",&x3,&y3,&x2,&y2);
if(k==0){
printf("No Answer\n");continue;
}
if(x2==x3 && y2==y3){
printf("0.00\n");continue;
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
for(h=1;h<=k;h++){
minx[i][j][h]=inf;
}
}
}
minx[x3][y3][k]=0;
bfs();
ans=inf;
for(i=1;i<=k;i++){
if(ans>minx[x2][y2][i]){
ans=minx[x2][y2][i];
}
}
if(ans==inf){
printf("No Answer\n");
}
else printf("%.2f\n",ans);
}
return 0;
}

hdu5433 Xiao Ming climbing的更多相关文章

  1. HDU 5433 Xiao Ming climbing dp

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

  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(bfs+三维标记)

    Problem Description   Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can ...

  4. HDU 5433 Xiao Ming climbing

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

  5. HDu 5433 Xiao Ming climbing (BFS)

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

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

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

  7. Hdu4349 Xiao Ming's Hope

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

  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. 用js实现打印九九乘法表

    用js在打印九九乘法表 思考 在学习了流程控制和条件判断后,我们可以利用js打印各式各样的九九乘法表 不管是打印什么样三角形九九乘法表,我们都应该找到有规律的地方,比如第一列的数字是什么规律,第一行的 ...

  2. Flask扩展点总结(信号)

    信号(源码) 信号,是在flask框架中为我们预留的钩子,让我们可以进行一些自定义操作. pip3 install blinker 根据flask项目的请求流程来进行设置扩展点 1.中间件 from ...

  3. ES6在工作中会用到的核心知识点讲解

    一.var, let, const 谈到ES6,估计大家首先肯定会想到var,let,const 咱就先谈谈这三者的区别 var a = 3; { var a = 4; } console.log(a ...

  4. 页面渲染html的过程

    浏览器渲染页面的一般过程: 1.浏览器解析html源码,然后创建一个 DOM树.并行请求 css/image/js在DOM树中,每一个HTML标签都有一个对应的节点,并且每一个文本也都会有一个对应的文 ...

  5. DDD领域驱动设计:领域事件

    1 前置阅读 在阅读本文章之前,你可以先阅读: DDD领域驱动设计是什么 DDD领域驱动设计:实体.值对象.聚合根 DDD领域驱动设计:仓储 MediatR一个优秀的.NET中介者框架 2 什么是领域 ...

  6. loj10161 叶子的颜色

    CQOI 2009 给一棵有 mm 个节点的无根树,你可以选择一个度数大于 11 的节点作为根,然后给一些节点(根.内部节点.叶子均可)着以黑色或白色.你的着色方案应保证根节点到各叶子节点的简单路径上 ...

  7. 在 ASP.NET Core 应用中使用 Cookie 进行身份认证

    Overview 身份认证是网站最基本的功能,最近因为业务部门的一个需求,需要对一个已经存在很久的小工具网站进行改造,因为在逐步的将一些离散的系统迁移至 .NET Core,所以趁这个机会将这个老的 ...

  8. 玩转IDEA项目结构Project Structure,打Jar包、模块/依赖管理全搞定

    前言 你好,我是A哥(YourBatman). 如何给Module模块单独增加依赖? 如何知道哪些Module模块用了Spring框架,哪些是web工程? IDEA如何打Jar包?打War包? 熟练的 ...

  9. 九:SpringBoot-整合Mybatis框架,集成分页助手插件

    九:SpringBoot-整合Mybatis框架,集成分页助手插件 1.Mybatis框架 1.1 mybatis特点 1.2 适用场景 2.SpringBoot整合MyBatis 2.1 核心依赖 ...

  10. Jenkins部署静态资源文件

    Jenkins部署静态资源文件 1.Jenkins部署静态资源文件 1.1 设置项目名称.参数(环境.分支)等 1.2 配置源码管理 1.3 配置构建参数 2.项目实战demo 2.1 demo1 部 ...