hdu 2059 龟兔赛跑 (dp)

dp[i]表示到i点为止需要的最短时间,枚举上一个状态dp[j],dp[j]是冲好电的情况。

然后就是根据数学方法计算j-i的时间t,那么dp[i]= min { dp[j] + t }

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#define B(x) (1<<(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned ui;
const int oo = 0x3f3f3f3f;
const ll OO = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define lson rt<<1
#define rson rt<<1|1
void cmax(int& a, int b){ if (b > a)a = b; }
void cmin(int& a, int b){ if (b < a)a = b; }
void cmax(ll& a, ll b){ if (b > a)a = b; }
void cmin(ll& a, ll b){ if (b < a)a = b; }
void cmax(double& a, double b){ if (a - b < eps) a = b; }
void cmin(double& a, double b){ if (b - a < eps) a = b; }
void add(int& a, int b, int mod){ a = (a + b) % mod; }
void add(ll& a, ll b, ll mod){ a = (a + b) % mod; }
const ll MOD = 1000000007;
const int maxn = 110;
double dp[maxn];
double dis[maxn];

int main(){
	//freopen("E:\\read.txt", "r", stdin);
	int N;
	double C, T, VR, VT1, VT2, L;
	while (scanf("%lf", &L) != EOF){
		scanf("%d %lf %lf", &N, &C, &T);
		scanf("%lf %lf %lf", &VR, &VT1, &VT2);
		for (int i = 1; i <= N; i++)
			scanf("%lf", &dis[i]);
		dis[0] = 0.0;
		dis[++N] = L;
		fill(dp, dp + N + 2, (double)oo);
		dp[0] = 0;
		for (int i = 1; i <= N; i++){
			for (int j = 0; j < i; j++){
				double t = 0.0;
				if (j != 0) t += T;
				if (dis[i] - dis[j] - C < eps) t += (dis[i] - dis[j]) / VT1;
				else t += C / VT1 + (dis[i] - dis[j] - C) / VT2;
				cmin(dp[i], dp[j] + t);
			}
		}
		if (dp[N] - L / VR < eps) printf("What a pity rabbit!\n");
		else printf("Good job,rabbit!\n");
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值