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.

 

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 DP方程:dp[i] = min(dp[i-1]+ss[i], dp[i-2]+dd[i-1])
#include <cstdio>
#include <iostream>
#include<cstring>
using namespace std;
int main()
{
int n,t,i,j;
int a[],b[],dp[];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(j=;j<=n;j++)
scanf("%d",&b[j]);
dp[]=a[];
for(i=;i<=n;i++)
dp[i]=min(dp[i-]+a[i],dp[i-]+b[i]);
int hh = dp[n]/;
int mm = dp[n]%/;
int ss = dp[n]%;
printf("%02d:%02d:%02d %s\n", (+hh)%, mm, ss, (hh+)%>? "pm": "am");
}
return ;
}

Tickets——H的更多相关文章

  1. ios开发之多线程资源争夺

    上一篇介绍了常用的多线程技术,目前开发中比较常用的是GCD,其它的熟悉即可.多线程是为了同步完成多项任务,不是为了提高运行效率,而是为了提高资源使用率来提高系统的整体性能,但是会出现多个线程对同一资源 ...

  2. cas-5.3.x接入REST登录认证,移动端登录解决方案

    一.部署cas-server及cas-sample-java-webapp 1.克隆cas-overlay-template项目并切换到5.3分支 git clone git@github.com:a ...

  3. 设计模式学习——代理模式(Proxy Pattern)之 强制代理(强校验,防绕过)

    上周温习了代理模式:http://www.cnblogs.com/chinxi/p/7354779.html 在此进行拓展,学习强制代理.但是发现网上大多例子都有个“天坑”(我是这么认为的),在得到代 ...

  4. 设计模式学习——代理模式(Proxy Pattern)

    放假啦~学生们要买车票回家了,有汽车票.火车票,等.但是,车站很远,又要考试,怎么办呢?找代理买啊,虽然要多花点钱,但是,说不定在搞活动,有折扣呢~ /// /// @file Selling_Tic ...

  5. CAS-4.2.7接入REST登录认证,移动端、C/S端登录解决方案

    一.发送GET请求获取RSA公钥和JSESSIONID 请求地址:/cas/login,请求类型:GET curl -I http://cas.gfstack.geo:8080/cas/login 返 ...

  6. [loj3366]嘉年华奖券

    联系绝对值的几何意义/分类讨论,不难发现若$n$张奖券上的数从小到大依次为$a_{i}$,则收益为$\sum_{i=1}^{\frac{n}{2}}a_{i+\frac{n}{2}}-a_{i}$ 假 ...

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

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

  8. H - Tickets dp

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

  9. H - Tickets

    Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a ...

随机推荐

  1. Servlet监听器

    一.servlet的8个监听器 场景 监听者接口 事件类型 你想知道一个web应用上下文中是否增加.删除或替换了一个属性 javax.servlet.ServletContextAttributeLi ...

  2. Hadoop-HBASE案例分析-Hadoop学习笔记<二>

    之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第八章的笔记 主要介绍HBase,一个分布式数据库的应用案例. 案例概况: 1)时间序列数据库(OpenTSD ...

  3. Programming with Objective-C ----------Encapsulating Data

    Most Properties Are Backed by Instance Variables By default, a readwrite property will be backed by ...

  4. java 环境变量java_home配置多加了 \ 导致zookeeper莫名其妙问题。

    平时开发其实不太用得到java_home.path.classpath之类的环境变量,但是在命令行下运行java则需要用上,所以配错就可能出现莫名其妙错误. 错误JAVA_HOME 配置:D:\Pro ...

  5. iOS应用动态部署方案

    iOS的动态部署能极大的节约成本.苹果的审核周期很长,有的时候,你可能不得不等待将近2个星期去上架你的新功能或者bug.所以动态部署是有价值的. 我这里讨论的情况不把纯web应用考虑在内,因为用户体验 ...

  6. C和指针 第九章 字符串 字符 字节

    C语言中没有字符串类型,字符串是以NUL结尾的字符数组组成的. 高级字符串查找: //计算字符串起始部分,有多少字符是在group中 size_t strspn(char const * str, c ...

  7. sublime text install packages报错

    汉化版的sublime text安装软件包的时候报错如下: There are no packages available for install 打开控制台,ctrl+~,然后看到如下错误: Pac ...

  8. Java中的Serializable接口transient关键字,及字节、字符、对象IO

    1.什么是序列化和反序列化Serialization是一种将对象转为为字节流的过程:deserialization是将字节流恢复为对象的过程. 2.什么情况下需要序列化a)当你想把的内存中的对象保存到 ...

  9. Excel 导出

    admin = Context.Request.Cookies["user"].Values["username"].ToString();           ...

  10. 父窗口jquery触发iframe按钮事件(转载)

    原文地址: http://blog.csdn.net/muziduoxi/article/details/11123923 <script type="text/javascript& ...