Skiing
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4668   Accepted: 1242   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

Dijkstra

用优先队列,否则可能会超时。还是比较直白的

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue> using namespace std;
#define MAX 9000000000
struct Node
{
int x,y;
double time;
double v;
Node (){};
Node (int x,int y,double time,double v)
{
this->x=x;
this->y=y;
this->time=time;
this->v=v;
}
friend bool operator <(Node a,Node b)
{
if(a.time==b.time)
return a.v<b.v;
return a.time>b.time;
}
};
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int n,m;
int v;
int vis[105][105];
int a[105][105];
double s[105][105];
void Dijsktra()
{
priority_queue<Node> q;
q.push(Node(1,1,0,v));
while(!q.empty())
{
Node term=q.top();
q.pop();
if(vis[term.x][term.y]) continue;
vis[term.x][term.y]=1;
for(int i=0;i<4;i++)
{
int xx=term.x+dir[i][0];
int yy=term.y+dir[i][1];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(vis[xx][yy]) continue;
if(s[xx][yy]>term.time+1.0/term.v)
{
s[xx][yy]=term.time+1.0/term.v;
q.push(Node(xx,yy,s[xx][yy],term.v*pow(2.0,a[term.x][term.y]-a[xx][yy]))); }
}
}
}
int main()
{
while(scanf("%d%d%d",&v,&n,&m)!=EOF)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{scanf("%d",&a[i][j]);s[i][j]=MAX;}
memset(vis,0,sizeof(vis));
s[1][1]=0;
Dijsktra();
printf("%.2f\n",s[n][m]);
}
return 0;
}

POJ 3037 Skiing(Dijkstra)的更多相关文章

  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 SPFA

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

  3. POJ 3037 Skiing

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

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

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

  5. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  6. poj 1556 (Dijkstra + Geometry 线段相交)

    链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  7. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  8. poj 3159 Candies dijkstra + queue

    题目链接: http://poj.org/searchproblem 题目大意: 飞天鼠是班长,一天班主任买了一大包糖果,要飞天鼠分发给大家,班里面有n个人,但是学生A认为学生B比自己多的糖果数目不应 ...

  9. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

随机推荐

  1. java通过CLASSPATH读取包内文件

    读取包内文件,使用的路径一定是相对的classpath路径,比如a,位于包内,此时可以创建读取a的字节流:InputStream in = ReadFile.class.getResourceAsSt ...

  2. Chrome应用技巧之颜色拾取

    之前在Chrome应用店找了个插件实现拾色功能.并且很不理想.不知道是不是曾经Chrome自带的开发工具没提供到拾色功能还是我没发现.今天无意中发现Chomer自带的开发工具可拾色,请看以下的GIF动 ...

  3. PhpStorm和PHPstudy配置调试参数(Xdebug),问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.

    配置phpstrom的Xdebug 问题描述: Error. Interpreter is not specified or invalid. Press "Fix" to edi ...

  4. 定时检测Memcached进程是否存在,若不存在自动启动它

    由于一台WEB服务器的Memcached死掉而导致在访问网站的某些页面时候打不开.下面脚本会自动检测Memcached的进程,如果挂掉则自动重启Memcached服务. vim memcached_c ...

  5. Android--&gt;Realm(数据库ORM)使用体验,lambda表达式

    Realm,为移动设备而生.替代 SQLite 和 Core Data. 非常庆幸,官方帮助文档有中文: https://realm.io/cn/docs/java/latest/ 尽管眼下最新的版本 ...

  6. SiteWhere物联网云平台架构

    SystemArchitecture系统架构 Thisdocument describes the components that make up SiteWhere and how theyrela ...

  7. app store上传图片显示错误:未能创建 屏幕快照

    在iTunes Connect中加入一个app后.加入屏幕快照时,依照要求的尺寸上传照片成功,可是在保存的时候提示"未能创建Screenshots for 4-inch iPhone5 an ...

  8. Linux下出现Read-only file system的解决办法

    正常运行中的网站,忽然间出现session目录不可写,连接服务器一看,任何关于写硬盘的命令都不能用,提示Read-only file system,使用一条命令即可搞定此问题: mount -o re ...

  9. C运行库和VC对应关系

    ## C运行库和VC对应关系----------------------------------------------------------------Msvcr60.DLL -- VC6Msvc ...

  10. springmvc中配置servlet初始化类

    <bean  id="InitStart" lazy-init="false" init-method="InitSystem" cl ...