POJ 3037 Skiing

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();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值