zoukankan      html  css  js  c++  java
  • HDU 1260 TICKETS (简单DP)

    ickets

    TimeLimit: 2000/1000 MS (Java/Others)  MemoryLimit: 65536/32768 K (Java/Others)
    64-bit integer IO format:%I64d
     
    Problem Description
    Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
    A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
    Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
    Input
    There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
    1) An integer K(1<=K<=2000) representing the total number of people;
    2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
    3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
    Output
    For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
    SampleInput
    2
    2
    20 25
    40
    1
    8
    SampleOutput
    08:00:40 am
    08:00:08 am

    状态转移方程为dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i])



    代码如下:
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include  <map>
    #include <iostream>
    using namespace std;
    typedef long long ll;
    const int MAXN=2000+10;
    int si[MAXN];
    int di[MAXN];
    int dp[MAXN];
    #define INF 0x3f3f3f3f
    int main()
    {
        int t,k,a,b,c,tmp;
        scanf("%d",&t);
        while(t--)
        {
          scanf("%d",&k);
          for(int i=1;i<=k;i++)
            scanf("%d",&si[i]);
          for(int i=1;i<=k-1;i++)
            scanf("%d",&di[i]);
          for(int i=1;i<=k;i++)
            dp[i]=INF;
            dp[1]=si[1];
          for(int i=2;i<=k;i++)
              dp[i]=min(dp[i-1]+si[i],dp[i-2]+di[i-1]);
          tmp=dp[k];
          a=tmp/3600+8;
          tmp=tmp%3600;
          b=tmp/60;
          tmp=tmp%60;
          c=tmp;
          if(a<12)
            printf("%02d:%02d:%02d am
    ",a,b,c);
          else
            printf("%02d:%02d:%02d pm
    ",a-12,b,c);
        }
        return 0;
    }

    一开始一不小心写成了       dp[i]=min(dp[i-2]+si[i-1]+si[i],dp[i-2]+di[i-1]);

    导致后面debug了很久

  • 相关阅读:
    centos创建本地yum仓库
    CentOSyum操作
    配置mysql5.5主从服务器(转)
    如何做好网站开发项目需求分析(转)
    我在寻求工作治理的方法(转)
    Centos下_MysqL5.7在使用mysqldump命令备份数据库报错:mysqldump: [Warning] Using a password on the command line interface can be insecure.
    Redis限制在规定时间范围内登陆错误次数限制
    Yaf框架的配置
    在Centos环境下安装兼容Apache2.4高版本SVN服务
    yaf框架加载全局公共函数
  • 原文地址:https://www.cnblogs.com/a249189046/p/8309445.html
Copyright © 2011-2022 走看看