H - 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <sstream>
using namespace std;
#define MAXN 2003
/*
求解买票的最短时间,可以单独买票可以两个人合买,给出所有人单独买票和两个人合伙所需时间,最后
输出时间注意一下格式即可
一开始想的是区间DP,发现不对。
dp[n] = max(dp[n-1]+a[n],dp[n-2]+a[n-1 到1])
*/
int dp[MAXN],a[MAXN],b[MAXN];//a是单独买,b是两人一起!
void Print(int time)
{
    int hour = time/3600,minute = time/60%60,second = time%60;
    bool am = (hour<4)?true:false;
    if(!am) hour = (8+hour)%12;
    else hour = 8+hour;
    if(hour<10)
        printf("0%d:",hour);
    else
        printf("%d:",hour);
    if(minute<10)
        printf("0%d:",minute);
    else
        printf("%d:",minute);
    if(second<10)
        printf("0%d ",second);
    else
        printf("%d ",second);
    if(am)
        printf("am\n");
    else
        printf("pm\n");
}
int main()
{
    int n,k;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&k);
        for(int i=1;i<=k;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<k;i++)
            scanf("%d",&b[i]);
        dp[1] = a[1];
        for(int i=2;i<=k;i++)
            dp[i] = min(dp[i-1]+a[i],dp[i-2]+b[i-1]);
        Print(dp[k]);
    }
}
时间: 2024-08-26 02:40:52

H - Tickets的相关文章

H - Tickets HDU 1260 (动态规划)

H - Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1260 Description Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sel

Tickets

H - Tickets 参考:Tickets--H 思路:对于每一个买票的人来说,只需要决定他是自己买票还是跟前面的人一块买票即可. 假设三个人 A B C,当 C 要跟 B 一块买票的时候,B 不能够跟 A 一起买. 那么状态方程就应该是dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]),保证了不会有一个人跟两个人一块买票的情况. 想清楚什么变什么不变. 代码: // Created by CAD on 2019/10/26. #include <bits/stdc++.

带导航栏的横向菜单

MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有直接的控件可以用.开始我想用之前的方法,将TableView和TableViewCell倒置,实现横向TableView:但是会出现一个问题,每个Cell中的文本,都被省略显示,类似显示“2月...”. 原因是,在倒置TableView之前,TableView的宽很小(相当于图中横向菜单的高),那么

POJ 2828 Buy Tickets(线段树--单点更新)

Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16196   Accepted: 8059 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year wa

Poj2828Buy Tickets线段树

倒着搞就可以了,先进会被后面覆盖. #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list> #include <set&g

[ACM] hdu 1260 Tickets (动态规划)

Tickets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Jesus, what a great movie! Thou

Ural 1036 Lucky Tickets

Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ID: 103664-bit integer IO format: %lld      Java class name: (Any) You are given a number 1 ≤ N ≤ 50. Every ticket has its 2N-digit number. We call a

DP [HDU 1260] Tickets

Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1191    Accepted Submission(s): 559 Problem Description Jesus, what a great movie! Thousands of people are rushing to the cinema. However

HDU 1260 Tickets (动规)

Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 924    Accepted Submission(s): 468 Problem Description Jesus, what a great movie! Thousands of people are rushing to the cinema. However,