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. bzoj 1059 [ZJOI2007]矩阵游戏——匈牙利算法

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1059 发现不管怎么换,同一列的元素还是在同一列,同一行的元素还是在同一行. 所以必要条件是每 ...

  2. vw单位相关

    1.相对于视口的宽度.视口被均分为100单位的vw h1 { font-size: 8vw; } 如果视口的宽度是200mm,那么上述代码中h1元素的字号将为16mm,即(8x200)/100 2.相 ...

  3. 一些js面试高频知识点的总结

    第一部分:Object Prototypes (对象原型) (1)定义一个方法,要求传入一个string类型的参数,然后将string的每个字符间加个空格返回,例如: spacify('hello w ...

  4. canvas用2d渲染出3d的感觉

    好久没有写博客了,深究动画其实也就是setTimeout setInterval requestAnimationFrame很多人可能不熟悉requestAnimationFrame但是事实上和set ...

  5. web服务器--nginx简介

    nginx 介绍Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务.Nginx是一款轻量级的Web 服务器/反向代理服务器及电 ...

  6. Win7下设置WiFi热点

    Win7下设置WiFi热点 今天研究了下Win7设置WIFI热点,Connectify神马的都是浮云~亲測可用,现拿出来分享下~ 1.点击"開始",再点击"执行" ...

  7. CentOS 7 yum 安装与配置MySQL5.7

    1.下载mysql源安装包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2.安装mysql源 yu ...

  8. Oracle ORA-01861

    Oracle 插入时间时 报错:ORA-01861: 文字与格式字符串不匹配 的解决办法 解决方法:   这个错误一般出现在时间字段上,即你插入的时间格式和数据库现有的时间格式不一致,解决的方法是格式 ...

  9. Leetcode50. Pow(x, n)(快速幂)

    实现 pow(x, n) ,即计算 x 的 n 次幂函数. 示例 1: 输入: 2.00000, 10 输出: 1024.00000 示例 2: 输入: 2.10000, 3 输出: 9.26100 ...

  10. Codeforces 113C

    题目链接 C. Double Happiness time limit per test 5 seconds memory limit per test 128 megabytes input sta ...