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. MySQL的隐式类型转换整理总结

    当我们对不同类型的值进行比较的时候,为了使得这些数值「可比较」(也可以称为类型的兼容性),MySQL会做一些隐式转化(Implicit type conversion). 比如下面的例子:   1 2 ...

  2. sql查询平均下单时间

    SQL查询订单平均审核时长 今天在写一个sql,需求是算一个订单在执行状态中的各个节点的时长 比如在订单中,状态0为开始接单,状态3为已经审核,那么现在需要计算每个客服的平均审核时长 像图中所示:这个 ...

  3. 如何查询进程中占用CPU的线程

    top -c             命令查找进程PID top -Hp PID          找进程中的线程号 echo %x 线程号   将线程转换成16进制 jstack PID |grep ...

  4. 关于Android SDK无法更新的解决办法

    最新摆弄PhoneGap打包,所以需要安卓的环境,配置后,sdk更新实在是在慢了,上网找了一下,可能被强了,所有总结如下办法,最后弄好了,跟大家分享一下 具体步骤:1:打开SDK Manager.ex ...

  5. python的高阶函数与匿名函数

    一.高阶函数的定义 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs) 结果:19 解释: ...

  6. 《Cracking the Coding Interview》——第4章:树和图——题目4

    2014-03-19 03:40 题目:给定一棵二叉树,把每一层的节点串成一个链表,最终返回一个链表数组. 解法:前序遍历,遍历的同时向各个链表里添加节点.水平遍历好像还不如前序遍历来得方便. 代码: ...

  7. Python第三方模块tesserocr安装

    介绍 在爬虫过程中,难免会遇到各种各样的验证码,而大多数验证码还是图形验证码,这时候我们可以直接用 OCR 来识别. tesserocr 是 Python 的一个 OCR 识别库 ,但其实是对 tes ...

  8. Springboot 启动问题

    每次以debug方式启动springboot之后都会在SilentExitExceptionHandler类中的throw new SilentExitException() 解决办法 :window ...

  9. os--留

    os.path.abspath(path) #返回绝对路径    绝对路径和文件路径的区别,绝对路径是当前在操作文本的路径,文件路径是当前文本的文件的路径 os.path.basename(path) ...

  10. echarts 柱状图下钻功能

    var drillDown = {   getOption : function () {   var option = null;   option = {   title: {   text: ' ...