解题思路:动态规划
状态转移方程:
d[i] = max(d[k] + TT) (0<j<i)
TT : k点充电,从k到i点距离时间
总共n+2点,n个充电站+起点+终点
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define clr(p,v) memset(p,v,sizeof(p))
const int maxn = 110 ;
int n, m, C, T;
int len, vr, vt, vt2;
int a[maxn];
double d[maxn];
int main()
{
while (~scanf("%d", &len))
{
//Input
scanf("%d%d%d", &n, &C, &T);
scanf("%d%d%d", &vr, &vt, &vt2);
a[0] = 0;
for (int i=1; i<=n; ++i) scanf("%d", &a[i]);
a[++n] = len;
//Caculate
double tVR = 1.0*len/vr;
d[0] = 0.0;
for (int i=1; i<=n; ++i)
{
int mi = min(a[i], C);
d[i] = 1.0*mi/vt + 1.0*(a[i]-mi)/vt2;
for (int j=i-1; j>0; --j)
{
int tt = a[i] - a[j];
int mi = min(tt, C);
double tLeft = 1.0*mi/vt+1.0*(tt-mi)/vt2;
d[i] = min(d[i], d[j]+T+tLeft);
}
}
//output
if (tVR < d[n]) puts("Good job,rabbit!");
else puts("What a pity rabbit!");
}
return 0;
}

6988

被折叠的 条评论
为什么被折叠?



