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;
}

最新文章

  1. [LintCode] Product of Array Except Self 除本身之外的数组之积
  2. zlog学习笔记(level)
  3. web前端本地测试方法
  4. MySql目录没有data文件夹怎么办
  5. 防止sql注入,过滤敏感关键字
  6. java:抽象类和抽象函数
  7. 八,WPF 命令
  8. Android开发艺术探索(三)——View的事件体系
  9. Django数据迁移
  10. android App Widgets
  11. windows服务器下IIS7 安装URL Rewrite(URL重写)模块
  12. calc() ---一个会计算的css属性
  13. bootstrap弹窗、弹出层、modal
  14. JMeter实现Oracle参数化(1)
  15. PAT A1153 Decode Registration Card of PAT (25 分)——多种情况排序
  16. Web 安全 之 OpenSSL
  17. [leetcode.com]算法题目 - Symmetric Tree
  18. Codeforces 12D Ball cdq分治
  19. Ubuntu 12.04 安装JDK
  20. 20169221 2016-2017-2《移动平台与android开发》学习总结

热门文章

  1. python-数据结构Data Structure1
  2. 消息队列 概念 配合SpringBoot使用Demo
  3. django学习笔记【004】创建带有model的app
  4. Mongodb更新数组$pull修饰符
  5. Spark-shell 启动WARN---java.net.BindException: Address already in use
  6. CefSharp 集成谷歌浏览器详解---(一)环境搭建(没测试过,不知道好不好用)
  7. 如何用手机访问电脑上的html文件
  8. Android之2D图形(圆、直线、点)工具类 (持续更新)
  9. dirname(__FILE__) 的使用总结 1(转)
  10. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配