• HDU1260DP


    Tickets

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


    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
     
    Source
     

     题意:

    处理k件事依次排列,每有一个件事单独处理时间,又知道相邻的两件事同时处理的时间,问这k件事最少的处理时间

    代码:

    //每件事考虑单独处理和他与前一个同时处理两种情况,dp求最小即可。
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int f[2][2003],n,k,a[2003],b[2003];
    int main()
    {
        scanf("%d",&n);
        while(n--){
            scanf("%d",&k);
            for(int i=1;i<=k;i++) scanf("%d",&a[i]);
            for(int i=2;i<=k;i++) scanf("%d",&b[i]);
            f[0][1]=a[1];f[1][1]=a[1];
            for(int i=2;i<=k;i++){
                f[0][i]=min(f[0][i-1]+a[i],f[1][i-1]+a[i]);
                f[1][i]=f[0][i-1]-a[i-1]+b[i];
            }
            int sum=min(f[0][k],f[1][k]);
            int se=sum%60;
            int mi=(sum/60)%60;
            int ho=((sum/60)/60)%60+8;
            int x1,x2,x3,x4,x5,x6,flag=0;
            if(ho>12) {ho-=12;flag=1;};
            x1=ho/10;x2=ho%10;x3=mi/10;x4=mi%10;x5=se/10;x6=se%10;
            printf("%d%d:%d%d:%d%d ",x1,x2,x3,x4,x5,x6);
            if(flag) printf("pm
    ");
            else printf("am
    ");
        }
        return 0;
    }
  • 相关阅读:
    2019春第九周作业
    2019春第八周作业
    2019春第七周作业
    2019春第六周作业
    2019春第五周作业
    2019年春季学期第四周作业
    2019年春季学期第三周作业
    2019年春季学期第二周作业
    学习进度条
    第六周作业
  • 原文地址:https://www.cnblogs.com/--ZHIYUAN/p/6551130.html
Copyright © 2020-2023  润新知