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了很久

  • 相关阅读:
    javascript 与 asp.net 的交互
    10 Mar 10 Auto Complete Ajax Scripts
    Asp.net性能优化总结
    window.print(); is not working in Safari Browser Windows XP
    用VS.NET中的测试工具(Application Center Test)测试ASP.NET程序
    ASP.NET页面事件过程多个用户控件时的执行过程
    Swt/Jface treeViewer的使用
    批量引入struts标签简化引入操作
    android学习笔记47android_手势识别技术的实现,手势库的创建
    学校举行的ACM,有道题没弄明白!!
  • 原文地址:https://www.cnblogs.com/a249189046/p/8309445.html
Copyright © 2011-2022 走看看