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 ...
随机推荐
- hdu_2899_Strange fuction(三分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2899 题意:让你解方程 题解:对于只有一个凸或者没有凸的图像,可以直接上三分解决. #include& ...
- 缓存1 静态缓存-->读库保存成php文件 mkdir-->file_put_contents-->var_export -->include
@mkdir()-->file_put_contents-->$data = "<?php\nreturn ".var_export($setting, tru ...
- List-----Array
1.Definition Arry数组是一种连续储存的List 储存方式:将线性表中的元素一次储存在连续的储存空间中. Computer's logical structure: 逻辑位置上相邻的元素 ...
- C#在Json反序列化中处理键的特殊字符
假设有如下Json 数据: 1.{ 2."id" : 1, 3."@value" : "this a @", 4."$p" ...
- GsonFormat 报错
GsonFormat原来也有bug 我是用GsonFormat来生成java bean的,但是运行起来居然报 Caused by: java.lang.NumberFormatException: E ...
- linux 进程监控和自动重启的简单实现
目的:linux 下服务器程序会因为各种原因dump掉,就会影响用户使用,这里提供一个简单的进程监控和重启功能. 实现原理:由定时任务crontab调用脚本,脚本用ps检查进程是否存在,如果不存在则重 ...
- docker !veth
https://github.com/docker/docker/issues/11889
- 获取Excel数据(或部分数据)并导出成txt文本格式
运行代码前先导入jxl架包,以下代码仅供参考: 测试excel文件(我要获取该excel的内容为省.县.乡.村.组和PH的值): ExcelTest01类代码如下: // 读取Excel的类 impo ...
- 安卓常用 widget
验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...
- 从市场运营角度谈Uber中国的第一批用户是怎么来的
声明:这篇文章是从http://www.010lm.com/redian/2016/0312/1206875.html转来的,分享给大家. 1)首先告诉用户Uber是做什么的?即培养用户品牌意识. 我 ...