标签:des style blog io ar os sp java for
linle
题目大意:龟兔赛跑,总长度为N,兔子以恒定速度VR跑,乌龟骑电动车
跑,当电动车有电的时候最多跑C幂,有电的时候以VT1速度跑,没电的时
候以VT2的速度跑,已知路上有N个充电站,给你N个充电站离起点的距离。
每次充电需要T秒,问最终乌龟有可能赢得比赛吗?
思路:为了计算每个加油站距离下个充电站的距离,可将起点和终点看做是
充电站。这样总共就有N+2个充电站,序号为0~N+1。从第一个充电站到
第N+1个充电站,计算出从第0个充电站到第j个充电站在充满电的情况下跑
到第i个充电站的最短时间dp[i]。最终答案就是dp[N+1]。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int INF = 100000000.0; int L,N,C,T,VR,VT1,VT2; int oil[110]; double dp[110],time; int main() { while(~scanf("%d",&L)) { memset(oil,0,sizeof(oil)); memset(dp,0,sizeof(dp)); scanf("%d%d%d",&N,&C,&T); scanf("%d%d%d",&VR,&VT1,&VT2); for(int i = 1; i <= N; i++) scanf("%d",&oil[i]); oil[0] = 0; oil[N+1] = L; dp[0] = 0; for(int i = 1; i <= N+1; i++) { double Min = INF; dp[i] = Min; for(int j = 0; j < i; j++) { int len = oil[i]-oil[j]; if(len < C) time = len*1.0/VT1; else time = C*1.0/VT1 + (len-C)*1.0/VT2; if(j!=0) time += T; if(Min > dp[j]+time); Min = dp[j]+time; } dp[i] = Min; } if(dp[N+1] > (L*1.0/VR)) printf("Good job,rabbit!\n"); else printf("What a pity rabbit!\n"); } return 0; }
标签:des style blog io ar os sp java for
原文地址:http://blog.csdn.net/lianai911/article/details/41540985