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

  1. 2
  2. 2
  3. 20 25
  4. 40
  5. 1
  6. 8

Sample Output

  1. 08:00:40 am
  2. 08:00:08 am
  3.  
  4. DP方程:dp[i] = min(dp[i-1]+ss[i], dp[i-2]+dd[i-1])
  1. #include <cstdio>
  2. #include <iostream>
  3. #include<cstring>
  4. using namespace std;
  5. int main()
  6. {
  7. int n,t,i,j;
  8. int a[],b[],dp[];
  9. scanf("%d",&t);
  10. while(t--)
  11. {
  12. scanf("%d",&n);
  13. for(i=;i<=n;i++)
  14. scanf("%d",&a[i]);
  15. for(j=;j<=n;j++)
  16. scanf("%d",&b[j]);
  17. dp[]=a[];
  18. for(i=;i<=n;i++)
  19. dp[i]=min(dp[i-]+a[i],dp[i-]+b[i]);
  20. int hh = dp[n]/;
  21. int mm = dp[n]%/;
  22. int ss = dp[n]%;
  23. printf("%02d:%02d:%02d %s\n", (+hh)%, mm, ss, (hh+)%>? "pm": "am");
  24. }
  25. return ;
  26. }

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接口定义了5种方法: init() service() destroy() getServletConfig() getServletInfo() init() 在Servlet实例化后 ...

  2. ahjesus Axure RP 7.0注册码

    ahjesus Axure RP 7.0注册码 用户名:axureuser 序列号:8wFfIX7a8hHq6yAy6T8zCz5R0NBKeVxo9IKu+kgKh79FL6IyPD6lK7G6+t ...

  3. HTTP的报文与状态码

    本文是<HTTP权威指南>的读书笔记 HTTP报文是简单的格式化数据块.每条报文都包含一条来自客户端的请求或一条来自服务器的响应.它们由三部分组成: 对报文进行描述的起始行(start l ...

  4. SQL/T-SQL实例参考

    ,D.[Score] B_Score ,'Distince'= CASE WHEN C.Score > D.Score THEN C.[Score] - D.[Score] WHEN C.Sco ...

  5. ASP.NET MVC中的两个Action之间值的传递--TempData

    一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在一个叫做TempData的Property,它的类型为TempDataDictiona ...

  6. ACM/ICPC 之 伞兵-最小割转最大流(POJ3308)

    //以行列建点,伞兵位置为单向边-利用对数将乘积转加法 //最小割转最大流 //Time:63Ms Memory:792K #include<iostream> #include<c ...

  7. 进程互斥和fork

    自父进程继承 进程的资格(真实(real)/有效(effective)/已保存(saved) 用户号(UIDs)和组号(GIDs)) 环境(environment) 堆栈 内存 打开文件的描述符(注意 ...

  8. October 24th Week 44th Monday 2016

    True love stories never have endings. 真正的爱情故事永远没有结局. It seems I have been customed to the single lif ...

  9. C实现栈和队列

    这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...

  10. Linux 安装基于(PHP5.5)memcache扩展

    一. memcache服务器端 下载地址:http://memcached.org/ 安装memcached,同时需要安装中指定libevent的安装位置 tar zxvf memcached-1.2 ...