标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12442 Accepted Submission(s):
4666
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int main () 8 { 9 int L; 10 int p[110]; 11 double dp[110]; 12 int n,c,T,VR,VT1,VT2; 13 while (~scanf("%d",&L)) 14 { 15 scanf("%d%d%d",&n,&c,&T); 16 scanf("%d%d%d",&VR,&VT1,&VT2); 17 for (int i=0; i<n; i++) 18 scanf("%d",&p[i]); 19 p[n]=L; //假使终点是最后一个充电站 20 memset(dp,0,sizeof(dp)); 21 if (p[0]<c) //初始化 22 dp[0]=p[0]*1.0/VT1; 23 else 24 dp[0]=(c*1.0/VT1)+(p[0]-c)*1.0/VT2; 25 for (int i=1; i<=n; i++) 26 { 27 if (p[i]<c) //特使判断从头到尾都不充电的情况 28 dp[i]=p[i]*1.0/VT1; 29 else 30 dp[i]=(c*1.0/VT1)+(p[i]-c)*1.0/VT2; 31 for(int j=0; j<i; j++) //查找并记录到这个第j个的充电站的最短时间 32 { 33 double t; 34 if (p[i]-p[j]<c) 35 t=(p[i]-p[j])*1.0/VT1; 36 else 37 t=(c*1.0/VT1)+(p[i]-p[j]-c)*1.0/VT2; 38 dp[i]=min(dp[j]+t+T,dp[i]); 39 } 40 } 41 if(dp[n]>L*1.0/VR) 42 printf("Good job,rabbit!\n"); 43 else 44 printf("What a pity rabbit!\n"); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4290063.html