HDOJ2059(龟兔赛跑 DP)

//dalao题解: http://acm.split.hdu.edu.cn/discuss/problem/post/reply.php?postid=13573&messageid=17&deep=1


#include <iostream> 

#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <math.h>
#include<iostream>

using namespace std;
#define INF  0xfffff;//0x代表十六进制
#define M 110

int a[M];
double dp[M]; //到达第i个电站的最短时间


double min(double x, double y)
{
return x > y ? y : x;
}


int main()
{
double l;
while (cin >> l) //总长度
{
int n; //电站数
double c, t;  // 满电距离 充电时间
double vr, v1, v2; //兔速 车速 龟速
cin >> n >> c >> t;
cin >> vr >> v1 >> v2;
for (int i = 1; i <= n; i++) cin >> a[i]; //电站距离 起点和终点都当做电站
a[0] = 0;
a[n + 1] = l;  
dp[0] = 0;
for (int i = 1; i <= n+1; i++)
{
dp[i] = INF;
for (int j = 0; j < i; j++)
{
double time;
double len = a[i] - a[j];   //两电站的距离
if (c >= len) time = len / v1; //可以到达电站
else time = c / v1 + (len - c) / v2;//不能到达电站
time += dp[j];
if (j > 0) time += t; //充电时间(起点不用充电)
dp[i] = min(dp[i], time);
}
}
if(dp[n+1]< l / vr)  cout << "What a pity rabbit!" << endl;
else cout << "Good job,rabbit!" << endl;
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值