码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 3037 Skiing

时间:2017-02-06 20:57:29      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:disco   get   个数   nes   each   turn   enter   题解   change   

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

Hint

Bessie‘s best route is: 
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

Source

USACO 2005 October Gold
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 const int maxn=105;
 8 const double Max_double=11258999068426240000;
 9 bool exist[maxn][maxn];
10 struct node{
11     int x,y;
12 };
13 node p;
14 double dis[maxn][maxn];
15 int map[maxn][maxn],v,n,m;
16 int dir[][2]={{0,-1},{1,0},{0,1},{-1,0}};
17 queue<node>q;
18 double SPFA(){
19     p.y=1;p.x=1;
20     dis[1][1]=0;exist[1][1]=true;
21     q.push(p);
22     while(!q.empty()){
23         p=q.front();q.pop();
24         exist[p.x][p.y]=false;
25         double k=1.0/(v * pow(2, 1.0*(map[1][1]-map[p.x][p.y])));
26         for(int i=0;i<4;i++){
27             int nex=p.x+dir[i][0],ney=p.y+dir[i][1];
28             if(nex>=1&&nex<=n&&ney>=1&&ney<=m){
29                 if(dis[nex][ney]>dis[p.x][p.y]+k){
30                     dis[nex][ney]=dis[p.x][p.y]+k;
31                     if(exist[nex][ney]==false){
32                         node tmp;
33                         tmp.x=nex;tmp.y=ney;
34                         q.push(tmp);exist[nex][ney]=true;
35                     }
36                 }
37             }
38         }
39     }
40     return dis[n][m];
41 }
42 int main()
43 {
44     scanf("%d%d%d",&v,&n,&m);
45     for(int i=1;i<=n;i++)
46       for(int j=1;j<=m;j++){
47           scanf("%d",&map[i][j]);dis[i][j]=Max_double;
48       }
49     memset(exist,false,sizeof(exist));
50     printf("%.2lf\n",SPFA());
51     return 0;
52 }

注:上面标红色的那个数反正是要开到非常大,我刚开始开了一个15亿左右的数,以为够用了,却总是WA,还找不出错了,造了几组数据也没毛病,后来看了看题解,只是觉得这里稍小了点,其余的感觉差不多。。

思路:很简单,就是我不想翻译英文,看的别人博客里翻译的,才知道了K,之后就是SPFA();

POJ 3037 Skiing

标签:disco   get   个数   nes   each   turn   enter   题解   change   

原文地址:http://www.cnblogs.com/suishiguang/p/6371575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!