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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <sstream>
using namespace std;
#define MAXN 2003
/*
求解买票的最短时间,可以单独买票可以两个人合买,给出所有人单独买票和两个人合伙所需时间,最后
输出时间注意一下格式即可
一开始想的是区间DP,发现不对。
dp[n] = max(dp[n-1]+a[n],dp[n-2]+a[n-1 到1])
*/
int dp[MAXN],a[MAXN],b[MAXN];//a是单独买,b是两人一起!
void Print(int time)
{
int hour = time/,minute = time/%,second = time%;
bool am = (hour<)?true:false;
if(!am) hour = (+hour)%;
else hour = +hour;
if(hour<)
printf("0%d:",hour);
else
printf("%d:",hour);
if(minute<)
printf("0%d:",minute);
else
printf("%d:",minute);
if(second<)
printf("0%d ",second);
else
printf("%d ",second);
if(am)
printf("am\n");
else
printf("pm\n");
}
int main()
{
int n,k;
scanf("%d",&n);
while(n--)
{
scanf("%d",&k);
for(int i=;i<=k;i++)
scanf("%d",&a[i]);
for(int i=;i<k;i++)
scanf("%d",&b[i]);
dp[] = a[];
for(int i=;i<=k;i++)
dp[i] = min(dp[i-]+a[i],dp[i-]+b[i-]);
Print(dp[k]);
}
}

H - Tickets的更多相关文章

  1. H - Tickets dp

    题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...

  2. Tickets——H

    H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...

  3. iOS 横向菜单

    MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有 ...

  4. H - Buy Tickets POJ - 2828 逆序遍历 树状数组+二分

    H - Buy Tickets POJ - 2828 这个题目还是比较简单的,其实有思路,不过中途又断了,最后写了一发别的想法的T了. 然后脑子就有点糊涂,不应该啊,这个题目应该会写才对,这个和之前的 ...

  5. Buy Tickets(线段树)

     Buy Tickets Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  6. HDU 1260 Tickets(简单dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  8. HDU-- Buy Tickets

    告知每次要插到第 i 个位置上,问最后它们的顺序是什么. 这一题,不是考线段树,是考如何想出用线段树...思维很巧妙,倒过来做的话就能确定此人所在的位置....   Buy Tickets Time ...

  9. poj 2828 Buy Tickets【线段树单点更新】【逆序输入】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16273   Accepted: 8098 Desc ...

随机推荐

  1. CentOS 7 配置 Nginx 正向代理 http、https 最详解

    手头项目中有使用到 nginx,因为使用的三方云服务器,想上外网需要购买外网IP的,可是有些需要用到外网却不常用的主机也挂个外网IP有点浪费了,便想使用nginx的反向代理来实现多台内网服务器使用一台 ...

  2. 洛谷 P2142 高精度减法(模板)

    题目描述 高精度减法 输入输出格式 输入格式: 两个整数a,b(第二个可能比第一个大) 输出格式: 结果(是负数要输出负号) 输入输出样例 输入样例#1: 2 1 输出样例#1: 1 说明 20%数据 ...

  3. python 操作数据库时遇到的错误

       pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; ch    之前的写法是从文件里 ...

  4. [SDOI2009]学校食堂

    题目描述 小F 的学校在城市的一个偏僻角落,所有学生都只好在学校吃饭.学校有一个食堂,虽然简陋,但食堂大厨总能做出让同学们满意的菜肴.当然,不同的人口味也不一定相同,但每个人的口味都可以用一个非负整数 ...

  5. [CREC2007/CQOI2014]robotic sort

    Description 一个实验室里有n个长短不一的试管.你的任务是编写一段程序,用机器臂把它们按照高度从小到大的顺序排列. 对于高度相同的试管,排序前后的相对位置应保持不变.排序方法如图所示. 排序 ...

  6. 题解报告:poj 1094 Sorting It All Out(拓扑排序)

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

  7. 6.12---Swagger中paramType---swagger的RequestParam和ApiImpliciParam----Example中方法带有selective

    paramType:表示参数放在哪个地方    header-->请求参数的获取:@RequestHeader(代码中接收注解)    query-->请求参数的获取:@RequestPa ...

  8. JavaScript判断

    if...else: if...else语句是在指定的条件成立时执行的代码,在条件不成立时执行else后的代码. 语法: if(条件) {条件成立时执行的代码 }else{ 条件不成立的时执行的代码} ...

  9. N18_二叉树的镜像

    题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...

  10. Java运算符法则

    JAVA运算符法则 运算符是一种特殊的符号,用于表示数据的运算,赋值和比较等: 算术运算符 正号+,负号-,加+,减-,乘*,除/,余或取模%,自增++,自减--,字符串相加+ 正号负号运算符代表运算 ...