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. Ubuntu 16.04 安装OpenSSH7.4

      前几天突然收到接到网安总队下发通知说我们在aws里面的服务器存在重大漏洞及安全隐患.必须在规定时间内修改.我们收到邮件打开Excel发现这些问题 是由于OpenSSH版本太低导致的.于是便安排紧急 ...

  2. POJ 3608 旋转卡壳

    思路: 旋转卡壳应用 注意点&边  边&边  点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdi ...

  3. Android 性能优化(14)网络优化( 10)Determining and Monitoring the Connectivity Status

    Determining and Monitoring the Connectivity Status This lesson teaches you to Determine if you Have ...

  4. 398 Random Pick Index 随机数索引

    给定一个可能含有重复元素的整数数组,要求随机输出给定的数字的索引. 您可以假设给定的数字一定存在于数组中.注意:数组大小可能非常大. 使用太多额外空间的解决方案将不会通过测试.示例:int[] num ...

  5. [ USACO 2001 OPEN ] 地震

    \(\\\) Description​ 给出一张 \(n\) 个点 \(m\) 条边的无向图,现在要建一棵生成树. 每条边都有消耗的时间 \(t_i\),也有建造的代价 \(w_i\) . 最后总金给 ...

  6. Git——github基本操作

    基本概念 上一篇文章写到git共享仓库,但是有个局限性,就是这个仓库存在于本地,其他人无法从我们这个仓库拿到共享的内容 但是我们可以将这个共享仓库放入一个远程的服务器上,然后设置一些登录权限就能完美的 ...

  7. Farseer.net轻量级开源框架 入门篇:使用前说明

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 框架性能测试 下一篇:Farseer.net轻量级开源框架 入门篇: 增.删.改. ...

  8. JPQL 模糊查询,查询条件拼接(like使用)

    @Transactional public List<ViewCorplist2> findAllCorpsLikeK(String kw) { System.out.println(kw ...

  9. canvas一周一练 -- canvas绘制中国银行标志(4)

    运行效果: <!DOCTYPE html> <html> <head> </head> <body> <canvas id=" ...

  10. (转)全文检索技术学习(一)——Lucene的介绍

    http://blog.csdn.net/yerenyuan_pku/article/details/72582979 本文我将为大家讲解全文检索技术——Lucene,现在这个技术用到的比较多,我觉得 ...