Tickets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7196    Accepted Submission(s): 3659

Problem 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

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = +;
int t[maxn];
int tt[maxn];
int dp[maxn][];
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
for (int i=; i<=n; i++) {
scanf("%d",&t[i]);
dp[i][]=;
dp[i][]=;
}
for(int i=; i<=n; i++) {
scanf("%d",&tt[i]);
}
tt[]=t[]; dp[][]=;
dp[][]=;
for(int i=; i<=n; i++) {
dp[i][]=min(dp[i-][],dp[i-][])+t[i]; if(i>) {
dp[i][]=min(dp[i-][],dp[i-][])+tt[i];
} else {
dp[i][]=t[i];
} }
int ans = min(dp[n][], dp[n][]); int h, m, s;
h = + ans/;
ans %= ;
m = ans/;
ans %= ;
s = ans;
if(h > ) {
h %= ;
printf("%02d:%02d:%02d pm\n",h, m, s);
} else {
printf("%02d:%02d:%02d am\n",h, m, s);
} }
}

DP———6.两个状态之间的 处理的更多相关文章

  1. jQuery获取Radio选择的Value值||两个select之间option的互相添加操作(jquery实现)

    jQuery获取Radio选择的Value值: 1. $("input[name='radio_name'][checked]").val();  //选择被选中Radio的Val ...

  2. PE知识复习之PE的两种状态

    PE知识复习之PE的两种状态 一丶熟悉PE的整体结构 从下面依次网上看.可以得出PE结构 其中DOS头有DOS头结构 也就是 IMAGE_DOS_HEADER 关于结构体的各项属性.前边已经写过了.本 ...

  3. EF Core中如何正确地设置两张表之间的关联关系

    数据库 假设现在我们在SQL Server数据库中有下面两张表: Person表,代表的是一个人: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ...

  4. DP问题如何确定状态

    DP问题如何确定状态 一.dp实质 动态规划的实质就是通过小规模的同类型的问题来解决题目的问题. 所以有一个dp数组来储存所有小规模问题的解. 所以确定状态也就是缩小问题规模. 我们求解问题的一般规律 ...

  5. [转]ASP.NET MVC中的两个Action之间值的传递--TempData

    本文转自:ASP.NET MVC中的两个Action之间值的传递--TempData 一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在 ...

  6. 【SSH】——Hibernate三种状态之间的转化

    Hibernate的三种状态为:transient.persistent和detached.对这三种状态的理解可以结合Session缓存,在Session缓存中的状态为persistent,另外两种不 ...

  7. Hibernate对象状态之间的神奇转换

    状态分类 在Hibernate框架中,为了管理持久化类,Hibernate将其分为了三个状态: 瞬时态(Transient Object) 持久态(Persistent Object) 脱管态(Det ...

  8. zabbix使用fping监控任意两个节点之间的网络质量、丢包率和响应时间

    zabbix使用fping监控任意两个节点之间的网络质量.丢包率和响应时间 之前的博文 使用zabbix3..4的ICMP Ping模版实现对客户端网络状态的监控 https://www.cnblog ...

  9. DOM的小练习,两个表格之间数据的移动

    本次讲的是两个表格之间数据的移动,左边的表格移动到右边,并且左边表格移动内容消失. <head>   <meta http-equiv="Content-Type" ...

随机推荐

  1. docker简介以及优缺点

    1.docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制, ...

  2. 【Ecshop】商品数据采集扩展

    一个自用的Ecshop商品数据采集程序 ->到此下载

  3. FreeBSD--如何最有效率的安装软件

    Freebsd 下如何最有效率的安装软件 From <https://www.cnblogs.com/apexchu/p/4131821.html> FreeBSD的默认下载工具是fetc ...

  4. 开放定址法——平方探测(Quadratic Probing)

    为了消除一次聚集,我们使用一种新的方法:平方探测法.顾名思义就是冲突函数F(i)是二次函数的探测方法.通常会选择f(i)=i2.和上次一样,把{89,18,49,58,69}插入到一个散列表中,这次用 ...

  5. python基础之生成器、三元表达式、列表生成式、生成器表达式

    生成器 生成器函数:函数体内包含有yield关键字,该函数执行的结果是生成器,生成器在本质上就是迭代器. def foo(): print('first------>') yield 1 pri ...

  6. 程序第一次启动推送跳转,handleOpenURL没法跳转的原因

    iOS 程序启动时总会调用application:didFinishLaunchingWithOptions:,其中第二个参数launchOptions为NSDictionary类型的对象,里面存储有 ...

  7. 《Cracking the Coding Interview》——第14章:Java——题目1

    2014-04-26 18:20 题目:从继承的角度,把构造函数设成private有什么意义? 解法:就不能继承了.单体模式里也这么干,目的是为了不让使用者自主生成对象,进行限制. 代码: // 14 ...

  8. 《Cracking the Coding Interview》——第2章:链表——题目2

    2014-03-18 02:24 题目:给定一个单链表,找出倒数第K个节点. 解法:让一个指针先走K步,然后俩指针一起走到尽头.当然也可以先走到尽头数出链表的长度,然后第二次少走K步.其实耗费的工夫是 ...

  9. USACO Section1.2 Transformations 解题报告

    transform解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  10. .Net导出Word和Excel

    using System; using System.Collections.Generic; using System.Linq; using System.Web; public class Ex ...