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下使用gcc编译mesa文件报undefined reference to symbol 'sin@@GLIBC_2.2.5和DSO missing from command line两个错误的解决方案

    一.概述 在Linux系统下使用gcc编译用C语言写的mesa的示例程序. 环境:Ubuntu Server 18.04.1 二.问题的出现 在Ubuntu下安装好mesa所需的库文件,将目标文件从g ...

  2. SFTP工具类

    1.SFTP搭建方法: 地址: http://www.jb51.net/article/101405.htm https://blog.csdn.net/helloloser/article/deta ...

  3. AT&T汇编指令

    GAS中每个操作都是有一个字符的后缀,表明操作数的大小. C声明 GAS后缀 大小(字节) char b 1 short w 2 (unsigned) int / long / char* l 4 f ...

  4. Cookie的简单实用

    作用域: 一个域名下的所有网页共用一套cookie. 几个封装好的工具方法: // 添加一个cookie function setCookie(name, value, iDay) { var oDa ...

  5. js---根据指定的顺序进行排序

    有一个数据列表,我需要根据根据ID依次来取里面的第9,3,8,4项,具体的实现方法. var arr = [ {id:1,title:'我是第一个'}, {id:2,title:'我是第二个'}, { ...

  6. Spark连接MongoDB之Scala

    MongoDB Connector for Spark Spark Connector Scala Guide spark-shell --jars "mongo-spark-connect ...

  7. pandas 基础操作 更新

    创建一个Series,同时让pandas自动生成索引列 创建一个DataFrame数据框 查看数据 数据的简单统计 数据的排序 选择数据(类似于数据库中sql语句) 另外可以使用标签来选择 通过位置获 ...

  8. Ubuntu 安装 JDK8

    安装python-software-properties $sudo apt-get install python-software-properties $sudo apt-get install ...

  9. Spring-Boot之Redis基础

    Spring-Boot之Redis基础 准备 Redis下载地址:github.com/MSOpenTech/redis/releases Redis数据库的默认端口号是 6379 开启Redis服务 ...

  10. Android adb调试

    1.首先是adb 修改 devices/amlogic/p201_iptv/system.prop service.adb.tcp.port=5555 或者直接在盒子串口下修改 system/buil ...