POJ - 3037 Skiing SPFA
Skiing
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
Hint
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
#include<stdio.h>
#include<math.h>
#include<float.h> //DBL_MAX头文件
#include<queue>
using namespace std; int a[][],b[][];
double dis[][],sp[][];
int t[][]={{,},{,},{-,},{,-}};
int v0,r,c;
struct Node{
int x,y;
}node;
double spfa(int x,int y)
{
int i,j;
queue<Node> q;
for(i=;i<=r;i++){
for(j=;j<=c;j++){
dis[i][j]=DBL_MAX;
}
}
dis[x][y]=;
node.x=x;
node.y=y;
q.push(node);
b[x][y]=;
while(q.size()){
int fx=q.front().x;
int fy=q.front().y;
q.pop();
b[fx][fy]=;
for(i=;i<;i++){
int tx=fx+t[i][];
int ty=fy+t[i][];
double t=sp[fx][fy];
if(tx<||ty<||tx>r||ty>c) continue;
if(dis[fx][fy]+t<dis[tx][ty]){
dis[tx][ty]=dis[fx][fy]+t;
if(!b[tx][ty]){
node.x=tx;
node.y=ty;
q.push(node);
b[tx][ty]=;
}
}
}
}
return dis[r][c];
} int main()
{
int i,j;
scanf("%d%d%d",&v0,&r,&c);
for(i=;i<=r;i++){
for(j=;j<=c;j++){
scanf("%d",&a[i][j]);
sp[i][j]=1.0/(v0*pow(2.0,a[][]-a[i][j])); //提前记录
}
}
printf("%.2f\n",spfa(,));
return ;
}
POJ - 3037 Skiing SPFA的更多相关文章
- 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
Skiing Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4810 Accepted: 1287 Special ...
- POJ 3037 Skiing(Dijkstra)
Skiing Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4668 Accepted: 1242 Special ...
- Skiing POJ 3037 很奇怪的最短路问题
Skiing POJ 3037 很奇怪的最短路问题 题意 题意:你在一个R*C网格的左上角,现在问你从左上角走到右下角需要的最少时间.其中网格中的任意两点的时间花费可以计算出来. 解题思路 这个需要发 ...
- POJ 3037 SPFA
题意: 思路: 我们可以发现 到每个点的速度是一样的 那这就成水题了-. 裸的SPFA跑一哈 搞定 //By SiriusRen #include <cmath> #include < ...
- POJ 1860(spfa)
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...
- poj 3621 二分+spfa判负环
http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i], ...
- poj 1847( floyd && spfa )
http://poj.org/problem?id=1847 一个水题,用来熟悉熟悉spfa和floyd的. 题意:有m条的铁路,要从x,到y, 之后分别就是条铁路与其他铁路的交点.第一个输入的为有n ...
- ACM: POJ 3259 Wormholes - SPFA负环判定
POJ 3259 Wormholes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
随机推荐
- git拉取远程分支到本地分支或者创建本地新分支
git fetch origin branchname:branchname 可以把远程某各分支拉去到本地的branchname下,如果没有branchname,则会在本地新建branchname g ...
- 【题解】 AT2134 Zigzag MST
[题解]AT2134 Zigzag MST 一道MST好题 \(Anson\)有云: 要么是减少边的数量. 要么是改变连接边的方式. 那么如何减少边的数量呢?很简单,把所有不可能对答案产生贡献的边去掉 ...
- JAVA使用相对路径读取配置文件
JAVA使用相对路径读取配置文件[align=center][/align][size=medium][/size] 在软件开发中经常遇到读取配置文件,以及文件定位问题.今天做个总结. (一) ...
- java开发环境搭建-1
安卓开发所需软件: JDK Eclipse Android-Sdk ADT 其中jdk的下载和安装,详细见http://www.cnblogs.com/zhuxiaohui/p/3620685.htm ...
- nginx.config配置文件模板
#user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log notice;#error_l ...
- zabbix使用mysql模板监控mysql
出现监控项访问拒绝的信息 解决方法是: 在 mysql的 my.cnf 配置中增加 [mysql] user=zabbix password=zabbix [mysqladmin] user=zabb ...
- React之jsx语法特性
jsx 语法,直接可以在js中使用html标签. 还可以通过花括号的形式,在html标签中,写js表达式. <div> { 1 + 2 } hello,world! </div> ...
- EOF的使用
1.我疑惑了 char a[20]; while(scanf("%s",a)!=EOF){ cout<<"hello"<<endl; } ...
- listen 59
Different Brain Regions Handle Different Music Types (Vivaldi) versus (the Beatles) . Both great. Bu ...
- AtCoder Beginner Contest 106 2018/08/18
A - Garden Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement There is a ...