zoukankan      html  css  js  c++  java
  • hdu 2059 龟兔赛跑 (dp)

    /*
    把起点和终点比作加油站,那总共同拥有n+2个加油站了,
    每次都求出从第0个到第j个加油站(j<i)分别在加满油的情况下到第i个加油站的最短时间dp[i],
    终于的dp[n+1]就是最优解了。

    */ # include <stdio.h> # include <algorithm> # include <string.h> # define INF 999999999; using namespace std; int main() { int L,n,c,t,i,j; double min1,tmp; int vr,vt1,vt2; int path[100010]; double dp[100010]; while(~scanf("%d%d%d%d",&L,&n,&c,&t)) { scanf("%d%d%d",&vr,&vt1,&vt2); path[0]=0; for(i=1; i<=n; i++) scanf("%d",&path[i]); path[n+1]=L; dp[0]=0; for(i=1; i<=n+1; i++) { dp[i]=INF; for(j=0; j<i; j++) { int ll=path[i]-path[j]; if(c>=ll) tmp=ll*1.0/vt1; else tmp=c*1.0/vt1+(ll-c)*1.0/vt2; if(j!=0) tmp+=t; if(dp[i]>dp[j]+tmp) dp[i]=dp[j]+tmp; } } if(dp[n+1]>L*1.0/vr) printf("Good job,rabbit! "); else printf("What a pity rabbit! "); } return 0; }


  • 相关阅读:
    [12.19模拟赛]矩形|扫描线+set
    网 络
    数组(二维)
    数组
    02-线程的三种创建方式
    01-线程(概念篇)
    IO流-文件操作
    Serializable 可串行化接口
    PrintStream 类
    ObjectIntputStream / ObjectOutputStream 类
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7201609.html
Copyright © 2011-2022 走看看