Tickets
Description
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
20 25
40
1
8
Sample Output
08:00:08 am
/*
题意:现在有n个人买票,每个人买票都耗费时间。每个人有两种选择,自己买票,和前面的人或者和后面的人一起买票,给出和前面的人
或者和后面的人一起买票耗费的时间。让你求出最少耗费的时间。 初步思路:dp[i]=max(dp[i],dp[i-1]-use_time[i-1]+double_time[i]);瞎想了一个状态转移方程试着搞一搞 #错误:直觉错了。想法没错,但是方程写错了,dp[i]表示前i个人话费的最少时间,考虑第i个人的时候,和前面的那个人一起买票,还
是自己买票,得出来状态转移方程:dp[i]=max(dp[i-2]+double[i],dp[i-1]+use_time[i-1]) #还是错:正在找原因。。。坑 说了用 am 和 pm 但是数据要求用24进制,另外有一个点,12:01用am 或者 pm 并没有错误
*/
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 2005
using namespace std;
int t,n;
int use_time[N];
int double_time[N];//double_time[i]表示第i个人和第i-1个人一起买票的前
int dp[N];
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&use_time[i]);
}
for(int i=;i<=n;i++){
scanf("%d",&double_time[i]);
}
dp[]=;//初始化没有人的时候时间是零
dp[]=use_time[];
for(int i=;i<=n;i++){
//自己买票,还是和前面的人一起买票
dp[i]=min(dp[i-]+use_time[i],dp[i-]+double_time[i]);
}
int h=,m=,s=;
h+=dp[n]/;
m+=dp[n]%/;
s+=dp[n]%;
if(h<) printf("%02d:%02d:%02d am\n",h,m,s);
else printf("%02d:%02d:%02d pm\n",h,m,s);
}
return ;
}
Tickets的更多相关文章
- POJ2828 Buy Tickets[树状数组第k小值 倒序]
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19012 Accepted: 9442 Desc ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- Tickets——H
H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...
- POJ 2828 Buy Tickets(线段树 树状数组/单点更新)
题目链接: 传送门 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Description Railway tickets were d ...
- 【poj2828】Buy Tickets
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- [poj2828] Buy Tickets (线段树)
线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...
- POJ 2828 Buy Tickets
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- Buy Tickets(线段树)
Buy Tickets Time Limit:4000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 【poj2828】Buy Tickets 线段树 插队问题
[poj2828]Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in ...
- ural 1217. Unlucky Tickets
1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...
随机推荐
- .NET Excel导出方法及其常见问题详解
摘要:.NET Excel导出方法及其常见问题详解. 一.Excel导出的实现方法 在.net 程序开发中,对于Excel文件的导出我们一共有三种导出方式: 利用文件输出流进行读写操作 这种方式的导出 ...
- 移动端touch事件实现页面弹动--小插件
动手之前的打盹 说实话真的是好久没有更新博客了,最近一直赶项目,身心疲惫:最关键的是晚上还要回去上一波王者,实在是忙啊! 这周下来,清闲了些许,或许是因为要到国庆的缘故吧,大家都显得无精打采.俗话说的 ...
- 开博近一年的感想 by 程序员小白
/* 好吧,这里的写博客应该理解为更宏观的写文章. */ 在去年的这个时候,我所知道的平台只有 CSDN 和博客园..然而 CSDN 的广告实在是不想吐槽了,选择博客园是一件非常自然的事情.要说开 ...
- 原创:工作指派问题解决方案---模拟退火算法C实现
本文忽略了对于模拟退火的算法的理论讲解,读者可参考相关的博文或者其他相关资料,本文着重于算法的实现: /************************************************ ...
- 前端基础之JavaScript
什么是JavaScript? JavaScript,也称ECMAScript,是一种基于对象和事件驱动并具有相对安全性并广泛用于客户端网页开发的脚本语言,同时也是一种广泛用于客户端Web开发的脚本语言 ...
- MongoDB的全文检索(Text Search)功能
自己的项目中用到了mongodb,需要做一个搜索功能,刚开始不知道怎么搞,查了mongodb有个全文检索功能. 全文检索分为两步 第一,建立索引 db.stores.createIndex( { na ...
- VB.net shell、IO.File.Open、Process.Start、Shellexecute API 运用经验总结
打开文件还有很多方法,但我了解到运用较多的是上面几种- -,为了防止以后忘记,先把了解到的写下来. 1.Shell 这个看了很多网页,最靠谱的运用方法: Shell("cmd.exe /c ...
- 关于python中的pickle函数
8-7参考阅读 - 读文件.写文件.异常处理.文件保存游戏.pickle数据转成文本的过程又被称为"序列化",即将对象状态转换为可保持或传输的格式的过程.对应的,从序列化的格式中解 ...
- zoj1109 水题(大神绕道) Language of FatMouse
Language of FatMouse Time Limit: 10 Seconds Memory Limit:32768 KB We all know that FatMouse doe ...
- WPF使用资源字典组织资源
转载:http://blog.163.com/wangzhenguo2005@126/blog/static/371405262010111413321728/ 首先在解决方案资源管理器中添加 ...