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. Android锁屏后数据改变的解决方案

    如果一个界面设置成横屏,那么锁屏再开启之后,会重新执行一遍onCreate()方法.对于这个问题的解决方案如下: 只需要在Menifest文件的activity相应标签下添加这行代码即可: andro ...

  2. SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)

    1.前言 使用框架都是较新的版本: Spring 4.0.2 RELEASE Spring MVC 4.0.2 RELEASE MyBatis 3.2.6 2.Maven引入需要的JAR包 2.1设置 ...

  3. PHP文件上传至另一台服务器

    PHP程序上传文件时,想指定上传到另一台服务器. move_uploaded_file这个方法第二个参数指定的存放路径需要和php程序文件一个服务器,没办法指定其他服务器的地址,本人才疏学浅,哪位大哥 ...

  4. ajax请求webservice的过程中遇到的问题总结

    前台用ajax的post方法,无法请求到webservice中的方法的时候,需要在配置文件中添加 web.config文件中的 <system.web> 节点下加入:<webServ ...

  5. redis部署

    下载软件 [root@localhost /]# wget http://download.redis.io/releases/redis-2.8.9.tar.gz 解压.编译.安装 [root@lo ...

  6. Android 设置启动界面

    启动界面的意义是为了让后台处理耗时的复杂工作,当工作处理完成后,即可进入主界面.相比让用户等待布局加载完成,使用一张图片作为启动背景,会带来更好的体验. 首先,需要建立一个简单的布局: <?xm ...

  7. 2016年11月24日--面向对象、C#小复习

    面对对象就是:把数据及对数据的操作方法放在一起,作为一个相互依存的整体——对象.对同类对象抽象出其共性,形成类.类中的大多数数据,只能用本类的方法进行处理.类通过一个简单的外部接口与外界发生关系,对象 ...

  8. html中表格元素的相关总结

    表格元素相关总结: 1.在CSS中,内部表元素(如td.tr.col等)生成矩形框,这些矩形框包含内容.内边距和边框,但没有外边距,因此如果定义外边距,浏览器将忽略该定义:对于table元素,外边距有 ...

  9. cookie 和session 区别

    会话技术: Cookie:客户端技术.将数据保存在客户端浏览器上.Cookie是有大小和个数的限制. Session:服务器端技术.将数据保存在服务器端.Session没有大小和个数限制.Sessio ...

  10. 当你在浏览器地址栏输入一个URL后回车,将会发生的事情?

    原文:http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/ 作为一个软件开发者,你一定会对网络应用如何工作有 ...