POJ 3037 Skiing(Dijkstra)
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("%.2fn",s[n][m]);
}
return 0;
}
- OpenCV人脸识别之一:数据收集和预处理
- FFRPC应用之Client/Server
- Java8新特性——StreamAPI(二)
- 从WordPress SQLi谈PHP格式化字符串问题
- 自己实现PC端jQuery版轮播图
- Tips for thrift
- Java8新特性——StreamAPI(一)
- springcloud学习手册-Hystrix(仪表盘说明)
- RedRabbit——基于BrokerPattern服务器框架
- C++任务队列与多线程
- 游戏服务器ID生成器组件
- Java8新特性——Lambda表达式(一)
- C++ FFLIB之FFRPC:多线程&多进程的scalability探索
- ffrpc-c++进程间(服务器端、客户端)通信框架
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 写代码?程序猿?你不能不懂的八大排序算法的Python实现
- Java开发编程规范:5.集合处理
- codeforce 272E Dima and Horses (假DFS)
- 网速慢?NO可能是路由器的原因?
- codeforce 272B Dima and Sequence
- 微软自家的.Net下的JavaScript引擎--- ClearScript
- HDU 1159.Common Subsequence【动态规划DP】
- Codeforce 270D Greenhouse Effect
- 地表最简单安装MySQL及配置的方法,没有之一
- HDOJ 1176 免费馅饼 -- 动态规划
- flex-grow计算公式
- Cypress系列(67)- 环境变量设置指南
- codeforce 270C Magical Boxes
- Java开发编程规范: 4.OOP 规约
- Codeforces 1323 div2题解ABC