Skiing
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4810   Accepted: 1287   Special Judge

Description

Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevations E (-25 <= E <= 25). In order to join FJ and the other cows at a discow party, she must get down to the bottom right corner as quickly as she can by travelling only north, south, east, and west.

Bessie starts out travelling at a initial speed V (1 <= V <= 1,000,000). She has discovered a remarkable relationship between her speed and her elevation change. When Bessie moves from a location of height A to an adjacent location of eight B, her speed is multiplied by the number 2^(A-B). The time it takes Bessie to travel from a location to an adjacent location is the reciprocal of her speed when she is at the first location.

Find the both smallest amount of time it will take Bessie to join her cow friends.

Input

* Line 1: Three space-separated integers: V, R, and C, which respectively represent Bessie's initial velocity and the number of rows and columns in the grid.

* Lines 2..R+1: C integers representing the elevation E of the corresponding location on the grid.

Output

A single number value, printed to two exactly decimal places: the minimum amount of time that Bessie can take to reach the bottom right corner of the grid.

Sample Input

1 3 3
1 5 3
6 3 5
2 4 3

Sample Output

29.00

Hint

Bessie's best route is: 
Start at 1,1 time 0 speed 1 
East to 1,2 time 1 speed 1/16 
South to 2,2 time 17 speed 1/4 
South to 3,2 time 21 speed 1/8 
East to 3,3 time 29 speed 1/4

Source

USACO 2005 October Gold
 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=;
const double Max_double=11258999068426240000;
bool exist[maxn][maxn];
struct node{
int x,y;
};
node p;
double dis[maxn][maxn];
int map[maxn][maxn],v,n,m;
int dir[][]={{,-},{,},{,},{-,}};
queue<node>q;
double SPFA(){
p.y=;p.x=;
dis[][]=;exist[][]=true;
q.push(p);
while(!q.empty()){
p=q.front();q.pop();
exist[p.x][p.y]=false;
double k=1.0/(v * pow(, 1.0*(map[][]-map[p.x][p.y])));
for(int i=;i<;i++){
int nex=p.x+dir[i][],ney=p.y+dir[i][];
if(nex>=&&nex<=n&&ney>=&&ney<=m){
if(dis[nex][ney]>dis[p.x][p.y]+k){
dis[nex][ney]=dis[p.x][p.y]+k;
if(exist[nex][ney]==false){
node tmp;
tmp.x=nex;tmp.y=ney;
q.push(tmp);exist[nex][ney]=true;
}
}
}
}
}
return dis[n][m];
}
int main()
{
scanf("%d%d%d",&v,&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%d",&map[i][j]);dis[i][j]=Max_double;
}
memset(exist,false,sizeof(exist));
printf("%.2lf\n",SPFA());
return ;
}

注:上面标红色的那个数反正是要开到非常大,我刚开始开了一个15亿左右的数,以为够用了,却总是WA,还找不出错了,造了几组数据也没毛病,后来看了看题解,只是觉得这里稍小了点,其余的感觉差不多。。

思路:很简单,就是我不想翻译英文,看的别人博客里翻译的,才知道了K,之后就是SPFA();

POJ 3037 Skiing的更多相关文章

  1. POJ 3037 Skiing(如何使用SPFA求解二维最短路问题)

    题目链接: https://cn.vjudge.net/problem/POJ-3037 Bessie and the rest of Farmer John's cows are taking a ...

  2. POJ 3037 Skiing(Dijkstra)

    Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4668   Accepted: 1242   Special ...

  3. POJ - 3037 Skiing SPFA

    Skiing Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day ...

  4. Skiing POJ 3037 很奇怪的最短路问题

    Skiing POJ 3037 很奇怪的最短路问题 题意 题意:你在一个R*C网格的左上角,现在问你从左上角走到右下角需要的最少时间.其中网格中的任意两点的时间花费可以计算出来. 解题思路 这个需要发 ...

  5. poj—— 3037 Saving Beans

    Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  6. POJ 3037 SPFA

    题意: 思路: 我们可以发现 到每个点的速度是一样的 那这就成水题了-. 裸的SPFA跑一哈 搞定 //By SiriusRen #include <cmath> #include < ...

  7. Skiing(最短路)

    poj——3037 Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4921   Accepted: 1315 ...

  8. 一步一步深入理解Dijkstra算法

    先简单介绍一下最短路径: 最短路径是啥?就是一个带边值的图中从某一个顶点到另外一个顶点的最短路径. 官方定义:对于内网图而言,最短路径是指两顶点之间经过的边上权值之和最小的路径. 并且我们称路径上的第 ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. 将unity3d项目嵌入到Android App中使用

    创建一个新的AndroidStudio app项目. 1.添加库文件:拷贝unity安装目录下的库文件:Unity\Editor\Data\PlaybackEngines\AndroidPlayer\ ...

  2. React动态import()

    React动态import() react-router@v4代码分离,推荐的import().这里分享webpack配置和使用方法. 首先安装两个必须的包 cnpm i react-loadable ...

  3. 转 消息队列之 RabbitMQ

    转 https://www.jianshu.com/p/79ca08116d57 消息队列之 RabbitMQ 预流 2017.05.06 16:03* 字数 4884 阅读 80990评论 18喜欢 ...

  4. MYSQL不能显示中文字,显示错误“ERROR 1366 (HY000): Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89'”

    或者建表时带上编码utf8 CREATE TABLE `students`( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR( ...

  5. python3 发邮件 smtplib & email 库

    嗨 实现了用163发送到qq的功能,遗留了两个问题: 1. 接收者list会报错:update:因为list[]会传递过去一个真的[]list,改成如下就可以了: before: maillist=[ ...

  6. python3.6:DLL load failed:找不到指定的模块(from PyQt5 import QtCore)

    本人小白搭建pyqt环境时遇到问题 运行代码 from PyQt5 import QtCore' 发现错误 ImportError: DLL load failed: 找不到指定的模块 这个问题折磨了 ...

  7. 思维水题:UVa512-Spreadsheet Tracking

    Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...

  8. python基础学习笔记——循环语句(while、for)

    while 循环 流程控制语句 while 1.基本循环 while 条件: # 循环体 # 如果条件为真,那么循环则执行 # 如果条件为假,那么循环不执行   2.break break 用于退出当 ...

  9. linux的vi和vim编辑器操作

    vi:linux内部的文本编辑器:vim:vi的增强版,具有程序编辑的能力. vi和vim的三种常见模式: (1)正常模式(一般模式):vim一打开就是这种模式,此模式下可以使用各种快捷键,比如复制粘 ...

  10. 各浏览器对 window.open() 的支持

    原文地址