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. 弹射起步~django

    sudo apt-get installl tree 开始创建工作目录 django-admin.py startproject mysite 创建一个名为 mysite的子目录,然后我们通过tree ...

  2. Spring + MyBaits java.lang.reflect.InvocationTargetException 启动日志报错

    调试发现 实例化 class org.apache.ibatis.logging.slf4j.Slf4jImpl时发生异常,所以 slf4j jar 问题解决: http://www.cnblogs. ...

  3. c++ 常用的几种重载操作符

    运算符可以作为普通函数,朋友函数或成员函数来重载.下面的经验法则可以帮助您确定哪种形式最适合于给定的情况: 如果你重载了赋值(=),下标([]),函数调用(())或成员选择( - >),那么它就 ...

  4. Appium安装说明

    1.安装Appium前,需要先安装node.js .node.js官方网站:https://nodejs.org/, 这里我以Windows 10为例进行安装,选择Windows installer( ...

  5. Random Query CodeForces - 846F

    题目 翻译: 给出一个n个数字的数列a[1],...,a[n],f(l,r)表示使a[l],a[l+1],...,a[r]组成的新序列中的重复元素只保留一个后,剩下元素的数量(如果l>r,则在计 ...

  6. linux查找命令(find)

    linux查找命令(find) 命令格式: find [目录] [选项] [选项的条件] 选项: -name:文件名称查找 -size:文件的大小来查找 -perm:文件的权限来查找 ①根据文件的名称 ...

  7. iOS开发隐藏tabBar的问题

    开发中遇到第一个页面需要显示tabBar,但是第二个页面不需要显示,当回到第一个页面的时候又需要显示的情况. 在第一个页面跳转到第二个页面的时候需要给第二个页面设置tabBar的隐藏 - (void) ...

  8. django 相关问题

    和数据库的连接 session的实现 django app开发步骤 python环境准备 数据库安装 model定义 url mapping定义 view定义 template定义 如何查看数据库里的 ...

  9. pip 安装管理失败解决

    问题: pip install ansible 错误: src/hash_template.c:361: warning: implicit declaration of function ‘Py_F ...

  10. CZ-python01-06

    练习代码 练习代码 # Python注释 # 注释不是越多越好,对于一目了然的代码,不需要添加注释 # 对于复杂的操作,应该在操作开始填上若干行注释 # 对于不是一目了然的代码,应在其行尾添加注释(为 ...