POJ 3037 Skiing(Dijkstra)
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 4668 | Accepted: 1242 | Special Judge |
Description
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
* Lines 2..R+1: C integers representing the elevation E of the corresponding location on the grid.
Output
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)的更多相关文章
- POJ 3037 Skiing(如何使用SPFA求解二维最短路问题)
题目链接: https://cn.vjudge.net/problem/POJ-3037 Bessie and the rest of Farmer John's cows are taking a ...
- 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 ...
- POJ 3037 Skiing
Skiing Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4810 Accepted: 1287 Special ...
- Skiing POJ 3037 很奇怪的最短路问题
Skiing POJ 3037 很奇怪的最短路问题 题意 题意:你在一个R*C网格的左上角,现在问你从左上角走到右下角需要的最少时间.其中网格中的任意两点的时间花费可以计算出来. 解题思路 这个需要发 ...
- POJ 2502 - Subway Dijkstra堆优化试水
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...
- poj 1556 (Dijkstra + Geometry 线段相交)
链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- poj 3159 Candies dijkstra + queue
题目链接: http://poj.org/searchproblem 题目大意: 飞天鼠是班长,一天班主任买了一大包糖果,要飞天鼠分发给大家,班里面有n个人,但是学生A认为学生B比自己多的糖果数目不应 ...
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
随机推荐
- 在云服务器上部署node.js服务器
本文档介绍腾讯云·万象优图服务端nodejs的部署和集成,搭建一个nodejs+nginx为基础,对web端或者移动端提供http签名接口服务的例子程序.注意:本文档只是简单的示例,展示了服务端为终端 ...
- C#面试题汇总2
http://www.cnblogs.com/wangjisi/archive/2010/06/14/1758347.html 用.net做B/S结构的系统,您是用几层结构来开发,每一层之间的关系以及 ...
- Mac 常用的手势
可以在触屏版-更多手势查看 技巧:前期慢慢滑动练习.一定要慢慢滑动,这样可以清楚的看出有没有产生效果,尤其注意大拇指滑动的感觉. 回到桌面:四指向外 打开Lanuchpad:四指向内 查看所有任务:三 ...
- phpexcel对于中文路径和中文名称的问题(有疑问)
phpexcel对于中文的文件名无法读取(我本地环境都是utf-8的编码) 是不是win系统识别都是gbk ?(需要把utf-8的字符串改为gbk) $file = "C:\\Users\\ ...
- c#各类型转byte[]或转回
var tmp = BitConverter.ToInt32(new byte[]{...}); var bytes = BitConverter.GetBytes(tmp); 而String转byt ...
- Jetty - Connector源码分析
1. 描述 基于Jetty-9.4.8.v20171121. Connector接受远程机器的连接和数据,允许应用向远程机器发送数据. 1.2 类图 从类图看出AbstractConnector继承C ...
- HDU 1867 A + B for you again(KMP算法的应用)
A + B for you again Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- oracle序列在insert into 语句中的使用
很多人创建了序列,但是在插入语句中不知道怎么使用,在此做个简单介绍. oracle序列有两个参数:nextval和currval,使用的时候,需要输入sequence_name.nextval或seq ...
- JQuery EasyUI dialog弹出框的 close 和 destroy
开发项目中(使用JQuery EasyUI),根据业务需要重叠弹出多个提示框的情况,会出现如下情况:页面出现两个div模块调用同一个弹出页面,页面的数据接受框元素不能实时存储数据解决方案: 使用$(t ...
- c++ 单例模式 对全局变量的替代
前段时间要实习一个充值接口,创建了一个类(就叫类A好了),这个类A要和另外3个类进行交互,3个类对类A修改的数据是对其他类可见的.这种情况我想到了3个方法: 1.static 静态成员,静态成员为该类 ...