码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj 1260(简单dp)

时间:2018-05-25 19:18:36      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:就是   cstring   mission   max   iss   lease   input   oid   repr   

Tickets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7051    Accepted Submission(s): 3587

 

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.
 
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<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int maxn=2006;
 6 int one[maxn],two[maxn];
 7 int dp[maxn];
 8 int out[4];
 9 
10 int my_min(int a,int b)
11 {
12     return a<b?a:b;
13 }
14 
15 void output(int ti)
16 {
17     if(ti==0){
18         if(out[3]>=12) cout << " pm" << endl;
19         else cout << " am"<<endl;
20         return ;
21     }
22     if(ti==3){
23         if(out[ti]<10) cout << "0" << out[ti];
24         else cout << out[ti];
25     }
26     else{
27         if(out[ti]<10) cout << ":0"<< out[ti];
28         else cout<< ":" << out[ti];
29     }
30     output(ti-1);
31 }
32 
33 int main()
34 {
35     ios_base::sync_with_stdio(0); cin.tie(0);
36     int T;
37     cin >> T;
38     while(T--){
39         int k;
40         memset( dp, 0, sizeof dp);
41         cin >> k;
42         for(int i=1;i<=k;i++)
43             cin >> one[i];
44         for(int i=2;i<=k;i++)
45             cin >> two[i];
46         dp[1]=one[1];
47         for(int i=2;i<=k;i++){
48             dp[i]=my_min( dp[i-1]+one[i], dp[i-2]+two[i]);
49         }
50 
51         out[1]=dp[k];
52         out[3]=8;
53         out[2]=out[1]/60;
54         out[1]=out[1]%60;
55         out[3]=out[3]+out[2]/60;
56         out[2]=out[2]%60;
57         output(3);
58     }
59     return 0;
60 }

我的超水输出。

看看大神的输出。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int maxn=2006;
 6 int one[maxn],two[maxn],dp[maxn];
 7 
 8 int my_min(int a,int b)
 9 {
10     return a<b?a:b;
11 }
12 
13 int main()
14 {
15     int T;
16     cin >> T;
17     while(T--){
18         int k;
19         memset( dp, 0, sizeof dp);
20         cin >> k;
21         for(int i=1;i<=k;i++)
22             cin >> one[i];
23         for(int i=2;i<=k;i++)
24             cin >> two[i];
25         dp[1]=one[1];
26         for(int i=2;i<=k;i++){
27             dp[i]=my_min( dp[i-1]+one[i], dp[i-2]+two[i]);
28         }
29         int temp,ss,hh,mm;
30         temp=dp[k];
31         char s[5];
32         ss=temp%60;
33         mm=(temp-ss)/60%60;
34         hh=(temp-ss-mm*60)/3600+8;
35         if(hh>=12)
36             strcpy( s, "pm");
37         else strcpy( s, "am");
38         printf("%02d:%02d:%02d %s\n",hh,mm,ss,s);
39     }
40     return 0;
41 }

 

hdoj 1260(简单dp)

标签:就是   cstring   mission   max   iss   lease   input   oid   repr   

原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9089748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!