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. 

InputThere 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. 
OutputFor 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 这个递推公式比较简单
#include <bits/stdc++.h>
#define M 2009
using namespace std; int n,k,a[M],t[M],dp[M];
int hh,mm,ss; int main()
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&k);
for(int i = 1; i <= k; i++)
scanf("%d",&a[i]);
for(int i = 2; i <= k; i++)
scanf("%d",&t[i]);
dp[1] = a[1];
for(int i = 2; i <= k; i++)
dp[i] = min(dp[i-1]+a[i],dp[i-2]+t[i]); hh = dp[k]/3600;
mm = (dp[k]%3600)/60;
ss = dp[k]%60; printf("%02d:%02d:%02d %s",( 8 + hh)%24,mm,ss,(8 + hh)%24 > 12 ? "pm\n" : "am\n");
} return 0;
}

HDU 1260的更多相关文章

  1. 【DP】HDU 1260

    HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是 ...

  2. 怒刷DP之 HDU 1260

    Tickets Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  3. 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets

    2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...

  4. Tickets HDU - 1260 水DP

    HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...

  5. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...

  6. (dp)Tickets --HDU --1260

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1260 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  7. HDU 1260 Tickets (普通dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others)   ...

  8. HDU - 1260 Tickets 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...

  9. HDU 1260 Tickets DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...

  10. 题解报告:hdu 1260 Tickets

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...

随机推荐

  1. 【LInux】统计某文件夹下目录的个数

    统计当前文件夹下文件的个数,包括子文件夹里的ls -lR|grep "^-"|wc -l 统计文件夹下目录的个数,包括子文件夹里的ls -lR|grep "^d" ...

  2. Linux下Qt Creator编辑器无法输入中文解决

    Ubuntu安装了搜狗输入法,在浏览器中可以使用,但是在Qt Creator中却无法输入中文. 解决办法: 执行sudo apt-get install fcitx-libs-qt5 该命令将库文件l ...

  3. Android的Base64的坑

    Base64.encodeToString加密后一直和Apache的对不上,多了换行符,最后使用了NO_WRAP就好了 Base64.encodeToString(src, Base64.URL_SA ...

  4. nginx的https和http共存反向代理配置

    一.设置http反向代理: upstream ly.com { server ; server ; } upstream home.ly.com { server ; server ; } 对应增加: ...

  5. JBPM工作流(二)——数据库表说明

    以下为JBMP的数据库说明(18张): 1 流程配置类数据库表: 1.1 JBPM_PROCESSDEFINITION:流程模版表 字段名 字段含义 主键 外键 ID_ 流程模版标识 √ × NAME ...

  6. ajax里post 设置请求头的编码格式

    我们常用的ajax形式就是post和get.post需要设置请求头,那么问题来了: 首先,为什么get不需要设置编码格式? 其次:不设置post请求头编码格式可以吗? 还有:常用的请求头编码格式有哪些 ...

  7. xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun

    原文地址 xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcru ...

  8. export及export default的区别

    在JavaScript ES6中,export与export default均可用于导出常量.函数.文件.模块等,你可以在其它文件或模块中通过import+(常量 | 函数 | 文件 | 模块)名的方 ...

  9. Oracle课程档案,第五天

    集合操作 desc job_history:改变历史职位 job_history:历史表 vnion:重复值只保留一个 去除重复值 ★★ vnion all: 把所有重复值保留 不去除重复值★★ in ...

  10. 阿里云 centos 服务器无法自动挂载 nas 的问题

    阿里云服务器 centos 7.3 ,开始是通过 fstab 配置的自动挂载: xxx.cn-hangzhou.nas.aliyuncs.com:/ /nas nfs4 auto 0 0 但服务器启动 ...