Tickets

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Problem Description

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

题意:有t组输入,每组输入有三行,有n个人买票,第二行表示这n个人买票的时间,第三行表示这个人跟前一个人一起买票的时间。

题解:用dp[i]表示第几个人买票,转移方程dp[i] = min(dp[i-1]+这个人买票的时间,dp[i-2]+这个人跟前一个人一起买票的时间)

其中dp[1] = a[1]。

这道题的数据有点弱,下面两种输出都过了

        if(h>=12)
{
h -= 12;
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
if(h>=12)
{
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
#include <iostream>
#include <cstdio> using namespace std; int main()
{
int t,n,i,dp[2050],a[2050],b[2050];
cin>>t;
while(t--)
{
cin>>n;
dp[0] = 0;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n-1;i++)
cin>>b[i];
dp[1] = a[1];
for(i=2;i<=n;i++)
dp[i] = min(dp[i-1] + a[i],dp[i-2] + b[i-1]);
int h,m,s;
h = dp[n] / 3600 + 8;
m = dp[n] / 60 % 60;
s = dp[n] % 60;
if(h>=24)
h %= 24;
if(h>=12)
{
h -= 12;
printf("%02d:%02d:%02d pm\n",h,m,s);
}
else
{
printf("%02d:%02d:%02d am\n",h,m,s);
}
}
return 0;
}

HDU-1260_Tickets的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

  10. HDU 2586

    http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h&g ...

随机推荐

  1. 基于bootstrap框架在ie8以下,兼容媒体查询[css样式]

    <style type="text/css"> /*基于bootstrap框架在ie8以下,兼容媒体查询*/ .row [class^="col-" ...

  2. Weekly 10 小结

    A题 模拟 T = int(input()) while T: T -= 1 s = raw_input() n = len(s) res, pre = 0, 0 for i in xrange(1, ...

  3. 8天入门wpf—— 第四天 模板

    今天说下wpf中的模板,前面一篇中我们讲到了style,但是style所能做的仅仅是在现有控件的基础上进行修修补补,但是如果我们想彻底颠覆控件样式,那么我们就必须使用这一篇所说的模板. 老外写书都喜欢 ...

  4. java开发岗位面试整理

    一.Java基础 1. String类为什么是final的 2. HashMap的源码,实现原理,底层结构. 3. 说说你知道的几个Java集合类:list.set.queue.map实现类. 4. ...

  5. python基础--迭代器、生成器、内置函数、面向对象编程

    迭代器:迭代器对象从集合的第一个元素开始访问,直到所有的元素都被访问完结束.迭代器只能往前不会后退 迭代:更新换代(重复)的过程,每次的迭代都必须基于上一次的结果 迭代器:迭代取值的工具 使用迭代器的 ...

  6. 优化 Tengine HTTPS 握手时间

    背景 网络延迟是网络上的主要性能瓶颈之一.在最坏的情况下,客户端打开一个链接需要DNS查询(1个 RTT),TCP握手(1个 RTT),TLS 握手(2个RTT),以及最后的 HTTP 请求和响应,可 ...

  7. js判断类型为数字的方法实现总汇——原生js判断isNumber()

    方法一[推荐]: 最容易想到的是用typeof来判断是否是number类型 ,但是如果为NaN会被认为也是number类型,因此我们需要使用isNaN来排除NaN的情况. function isNum ...

  8. 文件下载工具类 DownLoadUtil 实战

    package com.cloud.mina.util; import java.io.File; import java.io.FileInputStream; import java.io.IOE ...

  9. PHP数据加密和解密

    encrypt.php <?php /** * Passport 加密函数 * * @param string 等待加密的原字串 * @param string 私有密匙(用于解密和加密) * ...

  10. linux系统 (实验一)实验楼的课程笔记

    实验楼的课程笔记 tab 键是命令补全 输入 tail  find / 立刻卡住 这时候ctrl+c 可以终端当前指令 一些常用的指令 Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂停当前程序 ...