Tickets 基础DP
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2694 Accepted Submission(s): 1308
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.
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.
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.
2
20 25
40
1
8
08:00:08 am
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = ;
int one[maxn],two[maxn];
int dp[maxn];
void solve(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for(int i = ; i<=n; i++) scanf("%d",&one[i]);
for(int i = ;i<=n; i++) scanf("%d",&two[i]);
memset(dp,,sizeof(dp));
if(n == ) dp[n] = one[];
else{
dp[] = one[];
for(int i = ; i<=n; i++){
dp[i] = min(dp[i-]+one[i],dp[i-]+two[i]);
}
}
int s = dp[n];
int second,minute,hour;
second = s % ;
minute = s / % ;
hour = s / / % + ;
int flag = ;
if(hour>){
flag = ;
hour %= ;
}
if(hour < ) printf("");
printf("%d:",hour);
if(minute<) printf("");
printf("%d:",minute);
if(second<) printf("");
printf("%d ",second);
if(flag) printf("pm");
else printf("am");
printf("\n");
}
}
int main()
{
solve();
return ;
}
Tickets 基础DP的更多相关文章
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- M - 基础DP
M - 基础DP Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descriptio ...
- lightoj1004【基础DP】
从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...
随机推荐
- C++之文件输入输出
在这里遇见不少的问题,其中的路径问题就是在windows中,\\转义字符才能准确的表示路径 #include <iostream> #include <fstream> #in ...
- 一个forward_list C++primer
#include<iostream> #include<forward_list> using namespace std; int main() { forward_list ...
- 在Mac OS X系统下 用dd命令将iso镜像写入u盘
一. Mac下将ISO写入U盘可使用命令行工具dd,操作如下: 1.找出U盘挂载的路径,使用如下命令:diskutil list2.将U盘unmount(将N替换为挂载路径):diskutil unm ...
- AOP与动态代理有什么联系
曾遇到“AOP与动态代理有什么联系”的问题,现把个人观点整理如下: 我觉得,动态代理是AOP的主要实现手段之一,AOP是动态代理的一种应用深化 AOP是一种思想,或者是方法论,类似OOP,是OOP的有 ...
- 省市便利 UIPicherView
@property (strong,nonatomic) UIPickerView *pickerV; @property (strong,nonatomic) NSArray *arr; @prop ...
- wpf应用程序 打印标签
新建一个wpf应用程序,Xaml如下: <Window x:Class="CreateBarCodeDemo.MainWindow" xmlns="http://s ...
- Object.setPrototypeOf 方法的使用
将一个指定的对象的原型设置为另一个对象或者null(既对象的[[Prototype]]内部属性). 语法 Object.setPrototypeOf(obj, prototype) 参数 obj 将被 ...
- ignite通过注解配置查询
官方文档的叙述可能有些不清楚,我做了一个测试,并且可以成功运行,待会儿后面贴出小栗子. 两步操作: 第一步在属性值处贴上@QuerySqlField注解 第二部设置key和value类型 Person ...
- js里父页面与子页面的相互调用
一.在页面里用 open 打开的子页面: 1.子页面调用父页面的方法,包括子页面给父页面传值: window.opener.methodName(); window.opener.methodName ...
- 直接拿来用!Facebook移动开源项目大合集
直接拿来用!Facebook移动开源项目大合集 时间:2014-04-22 15:37 作者:唐小引 随着iOS依赖管理工具CocoaPods和大量第三方开源库成熟起来,业界积累了大量的优秀开源项目. ...