• HD2059龟兔赛跑(DP)


    题目链接

    直接拿来当贪心做了=_=,然后就懵逼了

    动态规划,本弱真没想到=_=

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 const double eps = 0.000001;
     7 const int INF = 0xffffff;
     8 int station[110];
     9 double dp[110];
    10 int l, n, c, t, vr, vt1, vt2;
    11 double get_time(int s, int tempc)
    12 {
    13     double gtime = 0;
    14     if(s > tempc)
    15     {
    16         gtime += 1.0 * tempc / vt1;
    17         gtime += (s - tempc) * 1.0 / vt2;
    18     }
    19     else
    20     {
    21         gtime += s * 1.0 / vt1;
    22     }
    23     return gtime;
    24 }
    25 int is_chong(int s, int tempc)
    26 {
    27     double chong_time = t + get_time(s, c);
    28     double not_chong_time = get_time(s, tempc);
    29     if(not_chong_time - chong_time > eps)
    30         return 1;
    31     return 0;
    32 }
    33 double get_min(double x, double y)
    34 {
    35     if(x - y > eps)
    36         return y;
    37     return x;
    38 }
    39 int main()
    40 {
    41     while(scanf("%d", &l) != EOF)
    42     {
    43         scanf("%d%d%d", &n, &c, &t);
    44         scanf("%d%d%d", &vr, &vt1, &vt2);
    45         for(int i = 1; i <= n; i++)
    46             scanf("%d", &station[i]);
    47         station[n + 1] = l;
    48         double rtime = 1.0 * l / vr;
    49         station[0] = 0;
    50         dp[0] = 0;
    51         for(int i = 1; i <= n + 1; i++)
    52         {
    53             dp[i] = INF;
    54             for(int j = i - 1; j >= 0; j--)
    55             {
    56                 double tempTime = 0;
    57                 int s = station[i] - station[j];
    58                 if(s > c)
    59                 {
    60                     tempTime = 1.0 * c / vt1;
    61                     tempTime += (s - c) * 1.0 / vt2;
    62                 }
    63                 else
    64                     tempTime = s * 1.0 / vt1;
    65                 if(j)
    66                     tempTime += t;
    67                 dp[i] = get_min(dp[i], dp[j] + tempTime);
    68             }
    69             /*
    70             int s = station[i] - station[i - 1];
    71             if(s > tempc)
    72             {
    73                 gtime += 1.0 * tempc / vt1;
    74                 gtime += (s - tempc) * 1.0 / vt2;
    75                 tempc = 0;
    76             }
    77             else
    78             {
    79                 gtime += s * 1.0 / vt1;  // 不知道什么时候手贱,这里把s写成了c,浪费了半个小时
    80                 tempc = tempc - s;
    81             }
    82             if(is_chong(station[i + 1] - station[i], tempc))
    83             {
    84                 gtime += t;
    85                 tempc = c;
    86             }
    87             */
    88         }
    89         //gtime += get_time(l - station[n], tempc);
    90         if(dp[n + 1] - rtime > eps)
    91             printf("Good job,rabbit!
    ");
    92         else
    93             printf("What a pity rabbit!
    ");
    94     }
    95     return 0;
    96 }
    View Code
  • 相关阅读:
    2015长春区域赛感想
    己亥清爽恢复系列之数据文件1篇:SYSTEM物理损坏或丢失(关键表空间)
    ecshop和jQuery冲突
    ecshop广告分析
    ecshop商品页增加编辑器fckeditor
    DIV自适应高度
    打个招呼
    jdk的wsimport方法实现webservice客户端调用服务
    jdk自带发布webservice服务
    Mysql数据库基本配置
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/5313211.html
Copyright © 2020-2023  润新知