每次BC都好心酸。。。

BFS+queue。。状态可以设为p_val[x][y][k],加上斗志的值。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std; char str[55];
int h[55][55];
double p_val[55][55][55];
bool vis[55][55][55]; struct Point{
int x,y,k;double p;
Point(){}
Point(int xx,int yy,int kk,double pp){
x=xx,y=yy,p=pp;k=kk;
}
bool operator<(const Point &a)const{
if(p>a.p)return true;
else if(p==a.p){
if(k<a.k) return true;
}
return false;
}
}; int dir[4][2]={
{0,1},
{0,-1},
{1,0},
{-1,0}
}; int bx,by,ex,ey;
priority_queue<Point>que; void slove(int n,int m,int k,Point bt){
memset(vis,false,sizeof(vis));
Point tmp;
//priority_queue<Point>que;
que.push(bt);
bool flag=false;
while(!que.empty()){
bt=que.top();
que.pop();
if(vis[bt.x][bt.y][bt.k]) continue;
vis[bt.x][bt.y][bt.k]=true; // cout<<bt.p<<endl;
if(bt.p>p_val[bt.x][bt.y][bt.k]&&bt.k<=1) continue;
for(int i=0;i<4;i++){
tmp.x=dir[i][0]+bt.x;
tmp.y=dir[i][1]+bt.y;
if(tmp.x>=1&&tmp.x<=n&&tmp.y>=1&&tmp.y<=m&&h[tmp.x][tmp.y]!=-1){
tmp.p=bt.p+fabs(h[bt.x][bt.y]-h[tmp.x][tmp.y])/(bt.k*1.0);
tmp.k=bt.k-1;
// cout<<tmp.p<<endl;
if(tmp.p<p_val[tmp.x][tmp.y][tmp.k]&&abs(ex-tmp.x)+abs(ey-tmp.y)<tmp.k){
p_val[tmp.x][tmp.y][tmp.k]=tmp.p;
que.push(tmp);
}
}
}
}
double ans=1e10;
for(int i=1;i<=k;i++)
ans=min(ans,p_val[ex][ey][i]);
if(ans==1e10)
puts("No Answer");
else printf("%.2f\n",ans);
} int main(){
int T,n,m,k;
scanf("%d",&T);
while(T--){
while(!que.empty())que.pop();
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%s",str+1);
for(int j=1;j<=m;j++){
for(int s=0;s<=k;s++) p_val[i][j][s]=1e10;
if(str[j]=='#')
h[i][j]=-1;
else{
h[i][j]=str[j]-'0';
}
}
}
scanf("%d%d",&bx,&by);
scanf("%d%d",&ex,&ey);
if(abs(ex-bx)+abs(ey-by)>k||k==0){
puts("No Answer");
continue;
}
if(bx==ex&&by==ey){
puts("0.00");
}
else{
slove(n,m,k,Point(bx,by,k,0));
} }
return 0;
}

HDU 5433的更多相关文章

  1. HDU 5433 Xiao Ming climbing 动态规划

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

  2. HDU 5433 Xiao Ming climbing dp

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

  3. HDU 5433 Xiao Ming climbing

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

  4. HDu 5433 Xiao Ming climbing (BFS)

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

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

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. [Swift通天遁地]七、数据与安全-(7)创建文件浏览器:以可视化的方式浏览沙箱文件

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. $P5018 对称二叉树$

    problem 一直忘记给这个题写题解了. 这题挺水的吧. 挺后悔当时没写出来. #ifdef Dubug #endif #include <bits/stdc++.h> using na ...

  3. win32绘图基础

     获取设备环境句柄: (1)WM_PAINT消息中: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps ...

  4. mybatis中映射文件和实体类的关联性

    mybatis的映射文件写法多种多样,不同的写法和用法,在实际开发过程中所消耗的开发时间.维护时间有很大差别,今天我就把我认为比较简单的一种映射文件写法记录下来,供大家修改建议,争取找到一个最优写法~ ...

  5. Codeforces_The least round way

    B. The least round way time limit per test 2 seconds memory limit per test 64 megabytes input standa ...

  6. linux安装mysql可视化工具MySQL-workbench 连接数据库 执行sql

    Step1:建立数据库连接 点击新建连接的按钮,符号是“+”的按钮,出现下图,在“Connection name”输入连接名称. 填写连接信息 输入数据库连接密码 测试连接: 再次点击连接时会要求输入 ...

  7. centos 7 配置nginx

    安装nginx: curl -o  nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0. ...

  8. jquery 对 table 的操作

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...

  9. js的一些工具类

    //写入cookie function setCookie(name, value) {     var Days = 30; //此 cookie 将被保存 30 天     var exp = n ...

  10. JavaScript 复杂判断的优雅写法

    JavaScript 复杂判断的优雅写法 <div> <input type="button" name="btn" value=" ...