zoukankan      html  css  js  c++  java
  • hdoj 1260(简单dp)

    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
    ",hh,mm,ss,s);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    网络字体图标制作说明
    一些Office365官方的文章连接
    使用Microsoft Graph API整合Office 365
    如何获取Azure 租户ID
    如何在Azure的管理门户中注册应用程序并且分配Graph API权限
    网页简单整合Skype
    如何在windows10中保持Hyper-V与VMWare同时存在
    苹果企业开发者账号申请步骤
    git 取消 文件夹 版本控制
    在 sql server 中,查询 数据库及数据库中各表的大小
  • 原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9089748.html
Copyright © 2011-2022 走看看