Tickets——H
H. Tickets
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
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
Sample Input
- 2
- 2
- 20 25
- 40
- 1
- 8
Sample Output
- 08:00:40 am
- 08:00:08 am
- DP方程:dp[i] = min(dp[i-1]+ss[i], dp[i-2]+dd[i-1])
- #include <cstdio>
- #include <iostream>
- #include<cstring>
- using namespace std;
- int main()
- {
- int n,t,i,j;
- int a[],b[],dp[];
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d",&n);
- for(i=;i<=n;i++)
- scanf("%d",&a[i]);
- for(j=;j<=n;j++)
- scanf("%d",&b[j]);
- dp[]=a[];
- for(i=;i<=n;i++)
- dp[i]=min(dp[i-]+a[i],dp[i-]+b[i]);
- int hh = dp[n]/;
- int mm = dp[n]%/;
- int ss = dp[n]%;
- printf("%02d:%02d:%02d %s\n", (+hh)%, mm, ss, (hh+)%>? "pm": "am");
- }
- return ;
- }
Tickets——H的更多相关文章
- ios开发之多线程资源争夺
上一篇介绍了常用的多线程技术,目前开发中比较常用的是GCD,其它的熟悉即可.多线程是为了同步完成多项任务,不是为了提高运行效率,而是为了提高资源使用率来提高系统的整体性能,但是会出现多个线程对同一资源 ...
- cas-5.3.x接入REST登录认证,移动端登录解决方案
一.部署cas-server及cas-sample-java-webapp 1.克隆cas-overlay-template项目并切换到5.3分支 git clone git@github.com:a ...
- 设计模式学习——代理模式(Proxy Pattern)之 强制代理(强校验,防绕过)
上周温习了代理模式:http://www.cnblogs.com/chinxi/p/7354779.html 在此进行拓展,学习强制代理.但是发现网上大多例子都有个“天坑”(我是这么认为的),在得到代 ...
- 设计模式学习——代理模式(Proxy Pattern)
放假啦~学生们要买车票回家了,有汽车票.火车票,等.但是,车站很远,又要考试,怎么办呢?找代理买啊,虽然要多花点钱,但是,说不定在搞活动,有折扣呢~ /// /// @file Selling_Tic ...
- CAS-4.2.7接入REST登录认证,移动端、C/S端登录解决方案
一.发送GET请求获取RSA公钥和JSESSIONID 请求地址:/cas/login,请求类型:GET curl -I http://cas.gfstack.geo:8080/cas/login 返 ...
- [loj3366]嘉年华奖券
联系绝对值的几何意义/分类讨论,不难发现若$n$张奖券上的数从小到大依次为$a_{i}$,则收益为$\sum_{i=1}^{\frac{n}{2}}a_{i+\frac{n}{2}}-a_{i}$ 假 ...
- H - Buy Tickets POJ - 2828 逆序遍历 树状数组+二分
H - Buy Tickets POJ - 2828 这个题目还是比较简单的,其实有思路,不过中途又断了,最后写了一发别的想法的T了. 然后脑子就有点糊涂,不应该啊,这个题目应该会写才对,这个和之前的 ...
- H - Tickets dp
题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...
- H - Tickets
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a ...
随机推荐
- Servlet接口五种方法介绍
Servlet接口定义了5种方法: init() service() destroy() getServletConfig() getServletInfo() init() 在Servlet实例化后 ...
- ahjesus Axure RP 7.0注册码
ahjesus Axure RP 7.0注册码 用户名:axureuser 序列号:8wFfIX7a8hHq6yAy6T8zCz5R0NBKeVxo9IKu+kgKh79FL6IyPD6lK7G6+t ...
- HTTP的报文与状态码
本文是<HTTP权威指南>的读书笔记 HTTP报文是简单的格式化数据块.每条报文都包含一条来自客户端的请求或一条来自服务器的响应.它们由三部分组成: 对报文进行描述的起始行(start l ...
- SQL/T-SQL实例参考
,D.[Score] B_Score ,'Distince'= CASE WHEN C.Score > D.Score THEN C.[Score] - D.[Score] WHEN C.Sco ...
- ASP.NET MVC中的两个Action之间值的传递--TempData
一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在一个叫做TempData的Property,它的类型为TempDataDictiona ...
- ACM/ICPC 之 伞兵-最小割转最大流(POJ3308)
//以行列建点,伞兵位置为单向边-利用对数将乘积转加法 //最小割转最大流 //Time:63Ms Memory:792K #include<iostream> #include<c ...
- 进程互斥和fork
自父进程继承 进程的资格(真实(real)/有效(effective)/已保存(saved) 用户号(UIDs)和组号(GIDs)) 环境(environment) 堆栈 内存 打开文件的描述符(注意 ...
- October 24th Week 44th Monday 2016
True love stories never have endings. 真正的爱情故事永远没有结局. It seems I have been customed to the single lif ...
- C实现栈和队列
这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...
- Linux 安装基于(PHP5.5)memcache扩展
一. memcache服务器端 下载地址:http://memcached.org/ 安装memcached,同时需要安装中指定libevent的安装位置 tar zxvf memcached-1.2 ...