题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2059
根据充电站将整个赛道分为一段一段,
只要每一段时间最短总的也就最短
麻烦的是,经过一个充电站选择不冲,但电瓶车里其实还会剩下一些电,所以还要知道经过每个充电站的剩余电量
将问题转化一下,当不冲电的时候,就等于没有加油站
所以
if(val[i] - val[j]<=C){
dp[i] = min(dp[i],dp[j] + (val[i] - val[j])/vt + T);
}
else{
dp[i] = min(dp[i],dp[j] + C/vt +(val[i] - C - val[j])/vc + T);
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=100+5;
const int INF=0x3f3f3f3f;
int Charge[maxn];
double d[maxn];
//d[i] 表示到第i个充电站,所花的最少时间
int main(int argc, char const *argv[])
{
int Long,N,C,T,VR,VT1,VT2;
while(cin>>Long)
{
cin>>N>>C>>T>>VR>>VT1>>VT2;
N++;
for (int i = 1; i <= N; ++i){
if(i<N) scanf("%d",&Charge[i]);
else Charge[i]=Long;
if(Charge[i]>C) d[i]=(double)C/VT1+(double)(Charge[i]-C)/VT2;
else d[i]=(double)Charge[i]/VT1;
}
for(int i=1;i<=N;i++)
for(int j=1;j<i;j++)
{
double dist=Charge[i]-Charge[j];
d[i]=min(d[i],d[j]+dist/VT2);
if(dist>C) d[i]=min(d[i],d[j]+(dist-C)/VT2+T+(double)C/VT1);
else d[i]=min(d[i],d[j]+dist/VT1+T);
}
cout<<(d[N]<(double)Long/VR?"What a pity rabbit!":"Good job,rabbit!")<<endl;
}
return 0;
}