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. javaweb基础(21)_两种开发模式

    SUN公司推出JSP技术后,同时也推荐了两种web应用程序的开发模式,一种是JSP+JavaBean模式,一种是Servlet+JSP+JavaBean模式. 一.JSP+JavaBean开发模式 1 ...

  2. Bootstrap标签页(Tab)插件

    标签页(Tab)在Bootstrap导航元素一章中简介过,通过结合一些data属性,您可以轻松地创建一些标签页界面.通过这个插件您可以把内容放置在标签页或胶囊式标签页甚至是下拉菜单标签页中. 用法 您 ...

  3. Spring中c3p0连接池的配置 及JdbcTemplate的使用 通过XML配置文件注入各种需要对象的操作 来完成数据库添加Add()方法

    通过配置文件XML方法的配置 可以使用非常简练的Service类 UserService类代码如下: package com.swift; public class UserService { pri ...

  4. iOS调用WebService接口

    首先有几点说在前面 一般,在请求URL的后面带有WSDL字样的需要调用WebService URL样式例子:http://ip:port/navigable/webservice/loginSeric ...

  5. React动态import()

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

  6. Sorted Union-freecodecamp算法题目

    Sorted Union 1.要求 写一个 function,传入两个或两个以上的数组,返回一个以给定的原始数组排序的不包含重复值的新数组. 换句话说,所有数组中的所有值都应该以原始顺序被包含在内,但 ...

  7. shell 练习题

    1.编写脚本/bin/per.sh,判断当前用户对指定参数文件,是否不可读并且不可写 read -p "Please Input A File: " file if [ ! -e ...

  8. Hogan的安装和使用

    Hogan的安装和使用 通过npm安装hogan: npm install hogan.js --save-dev CommonJs下的使用方式: // 引入hogan var hogan = req ...

  9. MySQL查询时,查询结果如何按照where in数组排序

    MySQL查询时,查询结果如何按照where in数组排序 在查询中,MySQL默认是order by id asc排序的,但有时候需要按照where in 的数组顺序排序,比如where in的id ...

  10. Python基础-os模块 sys模块

    sys模块 与操作系统交互的一个接口 文件夹相关 os.makedirs('dirname1/dirname2')    可生成多层递归目录 os.removedirs('dirname1')    ...