HDOJ2059(龟兔赛跑 DP)

来源:互联网 发布:mac切换窗口手势 编辑:程序博客网 时间:2024/05/16 19:55

//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;
}
原创粉丝点击