HDU - 1260 Tickets

Posted shiyu-coder

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 1260 Tickets相关的知识,希望对你有一定的参考价值。

题目:

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.

InputThere 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.
OutputFor 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.
Sample Input

2
2
20 25
40
1
8

Sample Output

08:00:40 am
08:00:08 am

分析:很简单的一道dp题,单层循环一遍即可,给的测试用例都很松,对于输出格式卡的不严。
 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 
 5 int Time[11]={0}; //每条队伍所花的时间
 6 int line[2001]={0}; //dp数组,表示到第几个人时所花的时间
 7 int oneT[2001]={0}; //每个人领票所花费的时间
 8 int twoT[2001]={0}; //两个人一起领票所花的时间
 9 int N=0,K=0;
10 
11 int main(){
12     cin >>N;
13     for(int t=0;t<N;t++){
14         cin >>K;
15         for(int k=0;k<K;k++){
16             cin >>oneT[k];
17         }
18         for(int k=0;k<K-1;k++){
19             cin >>twoT[k];
20         }
21         line[0]=oneT[0];
22         line[1]=min(oneT[0]+oneT[1],twoT[0]);
23         for(int i=2;i<K;i++){
24             line[i]=min(line[i-1]+oneT[i],line[i-2]+twoT[i-1]);
25         }
26         Time[t]=line[K-1];
27         int second=Time[t]%60;
28         int minute=(Time[t]%3600)/60;
29         int hour=(Time[t]/60)/60+8;
30         if(hour<=12){
31             printf("%02d:%02d:%02d am
",hour,minute,second);
32         }else{
33             hour-=12;
34             printf("%02d:%02d:%02d pm
",hour,minute,second);
35         }
36     }
37     system("pause");
38     return 0;
39 }

 


代码:

以上是关于HDU - 1260 Tickets的主要内容,如果未能解决你的问题,请参考以下文章

动态规划 hdu 1260 Tickets

HDU 1260: Tickets

HDU - 1260 Tickets

HDU 1260 Tickets (普通dp)

HDU 1260 Tickets (动规)

HDU 1260 Tickets (动态规划)