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. CSS中position和header和overflow和background

    <!DOCTYPE html> <!--CSS中position属性--> <html lang="en"> <head> < ...

  2. TZ_11_Spring-Boot的整合SpringMvc和MyBatis

    1.整合SpringMVC 虽然默认配置已经可以使用SpringMVC了,不过我们有时候需要进行自定义配置. 1>修改方式 通过application.yaml 此名字不需要使用@Propert ...

  3. 玩转webpack之webpack的entry output

    webpack的入口配置项表示要配置的文件就是开发环境或者生产环境 浏览器本身不能认识的一些东西必须经过webpack的编译才能认识,但是要去写的时候我们经常用到预编译什么的比如scss比如jsx甚至 ...

  4. 【solr】Solr5.5.4+Zookeeper3.4.6+Tomcat8搭建SolrCloud集群

    Solr5.5.4+Zookeeper3.4.6+Tomcat8搭建SolrCloud集群 SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力 ...

  5. 【solr】schemaFactory配置相关schema.xml

    schemaFactory配置相关schema.xml  关于schemaFactory的配置困扰我半天啦,下面来总结一下. 话说,好像是从5.0以后就已经没有schema.xml啦,这是由于Solr ...

  6. python基础(输出、变量、常量、数据类型、流程控制)

    输出 print print("Hello World!") # python2 和 python3 的区别 # python2 # coding:utf-8 print 123 ...

  7. Java问题解读系列之String相关---String、StringBuffer、StringBuilder的区别

    今天的题目是String.StringBuffer和StringBuilder的区别: 首先还是去官方的API看看对这三种类型的介绍吧,Go...... 一.继承类和实现接口情况 1.String类 ...

  8. mysql8下载安装及配置

    mysql8下载和安装 一.下载 官网地址:https://dev.mysql.com/downloads/mysql/8.0.html 选择“downloads”-->"mysql ...

  9. Git push 出错 [The remote end hung up unexpectedly] - 简书

    one day,my teamate using git push and occured this error. $ git push Counting objects: 2332669, done ...

  10. 获取电脑名和IP地址

    private string  GetHostNameAndIP( bool  isv4Orv6)        {            string HostName = Dns.GetHostN ...