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,代表t组测试数据,没组测试数据,第一行输入一个n代表n个人,第二行为n个整数代表票卖给每个人用的时间,第二行为n-1个数,代表卖给两个人(第i个人和第i+1个人,与上面的人对应)   用的时间;
   例如:
      3
      a[1] a[2] a[3]
      b[1] b[2]
   a[i]代表卖票给第i个人用的时间,b[i]代表同时卖票给第i个人和第i+1个人用的时间。
思路:
  定义数组a[i]记录单个人买票的时间b[i]记录两个人买票的时间,d[i]记录i个人买票的最短时间,根据
  d[i]=min(d[i-2]+b[i-1],d[i-1]+a[i])(i-2个人用的最短时间加第i-1和第i个人一起买票与i-1个人用的最短时间加第i个人买票的时间), 求出n个人买票用的最短时间,最后控制输出格式。
 #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a[],b[],d[];
int n;
scanf("%d",&n);
for(int i = ; i <= n ; i++)
{
scanf("%d",&a[i]);
}
for(int i = ; i <= n- ; i++)
{
scanf("%d",&b[i]);
}
d[]=;
d[]=a[];
for(int i = ; i <= n ; i++)
{
d[i]=min(d[i-]+b[i-],d[i-]+a[i]); //表示i个人买票用的最短时间
}
int s=d[n]%;
int m=d[n]/%;
int t=+d[n]//;
printf("%02d:%02d:%02d am\n",t,m,s);
}
}


杭电 1260 Tickets的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

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

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

  3. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  4. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  5. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  6. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  7. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  8. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  9. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

随机推荐

  1. springboot&mybatis 增删改查系列(二)

    数据库篇 我的数据库名为data0525,数据表名为user,其中有五列uid,uname,upass,usex,umessage.uid为主键并且自动生成,由于是练习表,所以并没有考虑设计的合理性. ...

  2. C++中virtual继承的深入理解

    今天专门看了一下虚继承的东西,以前都没怎么用过,具体如下:父类: 复制代码代码如下: class   CParent { .... }; 继承类的声明比较特别: class   CChild   :  ...

  3. nginx命令介绍

    [root@webmaster nginx]# ./sbin/nginx -h nginx version: nginx/1.12.2 Usage: nginx [-?hvVtTq] [-s sign ...

  4. Codeforces Round #410 (Div. 2) C

    Description Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1 ...

  5. Kruskal HDOJ 1233 还是畅通工程

    题目传送门 /* 最小生成树之kruskal算法--并查集(数据结构)实现 建立一个结构体,记录两点和它们的距离,依照距离升序排序 不连通就累加距离,即为最小生成树的长度 */ #include &l ...

  6. 牛客国庆集训派对Day_7

    A.Relic Discovery 题目描述 Recently, paleoanthropologists have found historical remains on an island in ...

  7. tsconfig.json No inputs were found in config file

    Build:No inputs were found in config file '/tsconfig.json'. Specified 'include' paths were '["* ...

  8. android开发学习 ------- MongoDB数据库简单理解

    首先说一下MongoDB是什么? MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. MongoDB 是一个基于分布式文件存储的数据库. N ...

  9. 刷ID卡的就餐系统

    需求分析:公司旧的考勤系统,缺 “就餐”功能模块,不能查询和统计每天的就餐人数.故需开发一个简易的“刷ID卡的就餐系统”,三 部 分组成,一部分为人事资料的增删改查,二部分为处理从“刷卡就餐机”采集的 ...

  10. 【学习笔记】后端中的MVC和前端MVVM的关系