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/,minute = time/%,second = time%;
bool am = (hour<)?true:false;
if(!am) hour = (+hour)%;
else hour = +hour;
if(hour<)
printf("0%d:",hour);
else
printf("%d:",hour);
if(minute<)
printf("0%d:",minute);
else
printf("%d:",minute);
if(second<)
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=;i<=k;i++)
scanf("%d",&a[i]);
for(int i=;i<k;i++)
scanf("%d",&b[i]);
dp[] = a[];
for(int i=;i<=k;i++)
dp[i] = min(dp[i-]+a[i],dp[i-]+b[i-]);
Print(dp[k]);
}
}

H - Tickets的更多相关文章

  1. H - Tickets dp

    题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...

  2. Tickets——H

    H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...

  3. iOS 横向菜单

    MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有 ...

  4. H - Buy Tickets POJ - 2828 逆序遍历 树状数组+二分

    H - Buy Tickets POJ - 2828 这个题目还是比较简单的,其实有思路,不过中途又断了,最后写了一发别的想法的T了. 然后脑子就有点糊涂,不应该啊,这个题目应该会写才对,这个和之前的 ...

  5. Buy Tickets(线段树)

     Buy Tickets Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  6. HDU 1260 Tickets(简单dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  8. HDU-- Buy Tickets

    告知每次要插到第 i 个位置上,问最后它们的顺序是什么. 这一题,不是考线段树,是考如何想出用线段树...思维很巧妙,倒过来做的话就能确定此人所在的位置....   Buy Tickets Time ...

  9. poj 2828 Buy Tickets【线段树单点更新】【逆序输入】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16273   Accepted: 8098 Desc ...

随机推荐

  1. jQuery——修改网页字体大小

    HTML: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <lin ...

  2. C#中接受一个非字符串的输入

    接受来自用户的值 System 命名空间中的 Console 类提供了一个函数 ReadLine(),用于接收来自用户的输入,并把它存储到一个变量中. 例如: int num; num = Conve ...

  3. Deepfakes教程及各个换脸软件下载

    源:https://blog.csdn.net/koest/article/details/80720078 Deepfakes目前用于深度换脸的程序基本都是用python编程语言基于tensorfl ...

  4. ACM_求补集的交集

    求补集的交集 Time Limit: 2000/1000ms (Java/Others) Problem Description: 给定一个集合,然后再给出两个该集合的子集,求他们对应补集的交集. I ...

  5. 转 phpmyadmin操作技巧:如何在phpmyadmin里面复制mysql数据库?

    对于每一个站长而言,都会遇到要进行网站测试的时候.这个时候,往往需要备份数据库.如果按照一般的操作方式,都是先把数据库导出并备份到本地,然后再服务器上测试.如果一切正常还好,一旦出了问题,就又得把数据 ...

  6. Android requestWindowFeature(Window.FEATURE_NO_TITLE)无效解决方法

    今天在<第一行代码>上学习做自定义标题栏,需要将系统自带的标题栏隐藏掉,使用自定义的标题栏,结果发现,requestWindowFeature(Window.FEATURE_NO_TITL ...

  7. 转载pcb设计详细版

    http://www.51hei.com/bbs/dpj-52438-1.html 详细的altium designer制作PCB步骤,按照步骤一步步的学习就会自己制作PCB模型 目 录 实验三  层 ...

  8. UVM基础之---Command-line Processor

    提供一个厂商独立的通用接口命令行参数,支持分类:   1. 基本参数和值:get_args,get_args_matches   2. 工具信息:get_tool_name(),get_tool_ve ...

  9. self和super的区别

    (1)self调用自己方法,super调用父类方法 (2)self是类,super是预编译指令 (3)[self class]和[super class]输出是一样的 ①当使用 self 调用方法时, ...

  10. QT,折腾的几天-----关于 QWebEngine的使用

    几天前,不,应该是更早以前,就在寻找一种以HTML5+CSS+Javascript的方式来写桌面应用的解决方案,为什么呢?因为前端那套可以随心所欲的写样式界面啊,恩.其实我只是想使用H5的一些新增功能 ...