Tickets

Tickets
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

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
 
/*
题意:现在有n个人买票,每个人买票都耗费时间。每个人有两种选择,自己买票,和前面的人或者和后面的人一起买票,给出和前面的人
    或者和后面的人一起买票耗费的时间。让你求出最少耗费的时间。

初步思路:dp[i]=max(dp[i],dp[i-1]-use_time[i-1]+double_time[i]);瞎想了一个状态转移方程试着搞一搞

#错误:直觉错了。想法没错,但是方程写错了,dp[i]表示前i个人话费的最少时间,考虑第i个人的时候,和前面的那个人一起买票,还
    是自己买票,得出来状态转移方程:dp[i]=max(dp[i-2]+double[i],dp[i-1]+use_time[i-1])


#还是错:正在找原因。。。坑 说了用 am 和 pm 但是数据要求用24进制,另外有一个点,12:01用am 或者 pm 并没有错误
*/
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 2005
using namespace std;
int t,n;
int use_time[N];
int double_time[N];//double_time[i]表示第i个人和第i-1个人一起买票的前
int dp[N];
int main(){
    // freopen("in.txt","r",stdin);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&use_time[i]);
        }
        for(int i=2;i<=n;i++){
            scanf("%d",&double_time[i]);
        }
        dp[0]=0;//初始化没有人的时候时间是零
        dp[1]=use_time[1];
        for(int i=2;i<=n;i++){
            //自己买票,还是和前面的人一起买票
            dp[i]=min(dp[i-1]+use_time[i],dp[i-2]+double_time[i]);
        }
        int h=8,m=0,s=0;
        h+=dp[n]/3600;
        m+=dp[n]%3600/60;
        s+=dp[n]%60;
        if(h<13) printf("%02d:%02d:%02d am\n",h,m,s);
        else printf("%02d:%02d:%02d pm\n",h,m,s);
    }
    return 0;
}

 

posted @ 2017-03-15 13:32  勿忘初心0924  阅读(244)  评论(0编辑  收藏  举报