Tickets

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

Submit Status

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
 
/*
题意:现在有n个人买票,每个人买票都耗费时间。每个人有两种选择,自己买票,和前面的人或者和后面的人一起买票,给出和前面的人
或者和后面的人一起买票耗费的时间。让你求出最少耗费的时间。 初步思路:dp[i]=max(dp[i],dp[i-1]-use_time[i-1]+double_time[i]);瞎想了一个状态转移方程试着搞一搞 #错误:直觉错了。想法没错,但是方程写错了,dp[i]表示前i个人话费的最少时间,考虑第i个人的时候,和前面的那个人一起买票,还
是自己买票,得出来状态转移方程:dp[i]=max(dp[i-2]+double[i],dp[i-1]+use_time[i-1]) #还是错:正在找原因。。。坑 说了用 am 和 pm 但是数据要求用24进制,另外有一个点,12:01用am 或者 pm 并没有错误
*/
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 2005
using namespace std;
int t,n;
int use_time[N];
int double_time[N];//double_time[i]表示第i个人和第i-1个人一起买票的前
int dp[N];
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&use_time[i]);
}
for(int i=;i<=n;i++){
scanf("%d",&double_time[i]);
}
dp[]=;//初始化没有人的时候时间是零
dp[]=use_time[];
for(int i=;i<=n;i++){
//自己买票,还是和前面的人一起买票
dp[i]=min(dp[i-]+use_time[i],dp[i-]+double_time[i]);
}
int h=,m=,s=;
h+=dp[n]/;
m+=dp[n]%/;
s+=dp[n]%;
if(h<) printf("%02d:%02d:%02d am\n",h,m,s);
else printf("%02d:%02d:%02d pm\n",h,m,s);
}
return ;
}

Tickets的更多相关文章

  1. POJ2828 Buy Tickets[树状数组第k小值 倒序]

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19012   Accepted: 9442 Desc ...

  2. ACM: FZU 2112 Tickets - 欧拉回路 - 并查集

     FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u P ...

  3. Tickets——H

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

  4. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)

    题目链接: 传送门 Buy Tickets Time Limit: 4000MS     Memory Limit: 65536K Description Railway tickets were d ...

  5. 【poj2828】Buy Tickets

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  6. [poj2828] Buy Tickets (线段树)

    线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...

  7. POJ 2828 Buy Tickets

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  8. Buy Tickets(线段树)

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

  9. 【poj2828】Buy Tickets 线段树 插队问题

    [poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in ...

  10. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

随机推荐

  1. 使用gc、objgraph干掉python内存泄露与循环引用!

    Python使用引用计数和垃圾回收来做内存管理,前面也写过一遍文章<Python内存优化>,介绍了在python中,如何profile内存使用情况,并做出相应的优化.本文介绍两个更致命的问 ...

  2. 基于NIO和BIO的两种服务器对比

    基于BIO的服务器,服务端可能要同时保持几百万个HTTP连接,而这些连接并不是每时每刻都在传输数据,所以这种情况不适合使用BIO的服务器:而且需要保证共享资源的同步与安全,这个实现起来相对复杂.这时候 ...

  3. ssh (免密码登录、开启服务)

    ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以Unbutun为例.有机器A(192.168.1.155),B(192.168.1.181).现想 ...

  4. hdu 4090--GemAnd Prince(搜索)

    题目链接 Problem Description Nowadays princess Claire wants one more guard and posts the ads throughout ...

  5. Java数据结构和算法总结-冒泡排序、选择排序、插入排序算法分析

    前言:排序在算法中的地位自然不必多说,在许多工作中都用到了排序,就像学生成绩统计名次.商城商品销量排名.新闻的搜索热度排名等等.也正因为排序的应用范围如此之广,引起了许多人深入研究它的兴趣,直至今天, ...

  6. Apache shiro的简单介绍与使用(与spring整合使用)

    apache shiro框架简介 Apache Shiro是一个强大而灵活的开源安全框架,它能够干净利落地处理身份认证,授权,企业会话管理和加密.现在,使用Apache Shiro的人越来越多,因为它 ...

  7. fitnesse - Variables and Symbols

    fitnesse - Variables and Symbols 2017-09-30 目录 1 Variables(静态变量)  1.1 定义及使用  1.2 Variable作用域    1.2. ...

  8. zoj 1889 ones 数学

    Ones Time Limit: 2 Seconds      Memory Limit: 65536 KB Given any integer 0 <= n <= 10000 not d ...

  9. 解决Android5.0以下Dialog引起的内存泄漏

    最近项目开发中,开发人员和测试人员均反应在android5.0以下手机上LeakCanary频繁监控到内存泄漏,如下图所示,但凡用到Dialog或DialogFragment地方均出现了内存泄漏. 如 ...

  10. Weave Scope 多主机监控 - 每天5分钟玩转 Docker 容器技术(81)

    除了监控容器,Weave Scope 还可以监控 Docker Host. 点击顶部 HOSTS 菜单项,地图将显示当前 host. 与容器类似,点击该 host 图标将显示详细信息. host 当前 ...