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.
InputThere 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.
OutputFor 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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <sstream>
using namespace std;
#define MAXN 2003
/*
求解买票的最短时间,可以单独买票可以两个人合买,给出所有人单独买票和两个人合伙所需时间,最后
输出时间注意一下格式即可
一开始想的是区间DP,发现不对。
dp[n] = max(dp[n-1]+a[n],dp[n-2]+a[n-1 到1])
*/
int dp[MAXN],a[MAXN],b[MAXN];//a是单独买,b是两人一起!
void Print(int time)
{
int hour = time/,minute = time/%,second = time%;
bool am = (hour<)?true:false;
if(!am) hour = (+hour)%;
else hour = +hour;
if(hour<)
printf("0%d:",hour);
else
printf("%d:",hour);
if(minute<)
printf("0%d:",minute);
else
printf("%d:",minute);
if(second<)
printf("0%d ",second);
else
printf("%d ",second);
if(am)
printf("am\n");
else
printf("pm\n");
}
int main()
{
int n,k;
scanf("%d",&n);
while(n--)
{
scanf("%d",&k);
for(int i=;i<=k;i++)
scanf("%d",&a[i]);
for(int i=;i<k;i++)
scanf("%d",&b[i]);
dp[] = a[];
for(int i=;i<=k;i++)
dp[i] = min(dp[i-]+a[i],dp[i-]+b[i-]);
Print(dp[k]);
}
}
H - Tickets的更多相关文章
- H - Tickets dp
题目链接: https://cn.vjudge.net/contest/68966#problem/H AC代码; #include<iostream> #include<strin ...
- Tickets——H
H. Tickets Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this i ...
- iOS 横向菜单
MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有 ...
- H - Buy Tickets POJ - 2828 逆序遍历 树状数组+二分
H - Buy Tickets POJ - 2828 这个题目还是比较简单的,其实有思路,不过中途又断了,最后写了一发别的想法的T了. 然后脑子就有点糊涂,不应该啊,这个题目应该会写才对,这个和之前的 ...
- Buy Tickets(线段树)
Buy Tickets Time Limit:4000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU 1260 Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- poj 2828 Buy Tickets (线段树(排队插入后输出序列))
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissio ...
- HDU-- Buy Tickets
告知每次要插到第 i 个位置上,问最后它们的顺序是什么. 这一题,不是考线段树,是考如何想出用线段树...思维很巧妙,倒过来做的话就能确定此人所在的位置.... Buy Tickets Time ...
- poj 2828 Buy Tickets【线段树单点更新】【逆序输入】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 16273 Accepted: 8098 Desc ...
随机推荐
- codechef: BINARY, Binary Movements
非常有毛病的一道题,我一个一个读字符死活过不去,改成整行整行读就 A 了... 做法就是...最小点覆盖... 我们发现可以把一个点向上跳看做被吃掉了,然后最顶层的点是无法向上跳所以不能被吃掉,然后被 ...
- Codefoces 828C
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Hadoop Hive概念学习系列之HiveQL编译基础(十)
由客户端提交的HiveQL语句将最终被转换为一个或多个MapReduce任务并提交由Hadoop执行.不包含聚合和连接的简单SELECT语句可以使用一个单独的只包含Map阶段的任务实现.使用GROUP ...
- [ CodeForces 1065 B ] Vasya and Isolated Vertices
\(\\\) \(Description\) 求一个\(N\)个点\(M\)条边的无向图,点度为 \(0\) 的点最多和最少的数量. \(N\le 10^5,M\le \frac {N\times ( ...
- Django基础之admin功能
Django默认开起了后台 1.访问admin后台 2.用户和密码进行登录 ============================================================== ...
- 【译】x86程序员手册30-8.2 I/O指令
8.2 I/O Instructions I/O指令 The I/O instructions of the 80386 provide access to the processor's I/O p ...
- JSP参数传递兼EL表达式
1.浏览器?方式传递参数 /** 浏览器地址栏输入?方式传递参数 ?test=123 */ 可以用${param.test}方式输出 2.页面内部设置参数setAttribute /** JSP页面中 ...
- jstree的基本应用----记录
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- Linux文件排序和FASTA文件操作
文件排序 seq: 产生一系列的数字; man seq查看其具体使用.我们这使用seq产生下游分析所用到的输入文件. # 产生从1到10的数,步长为1 $ seq 1 10 1 2 3 4 5 6 7 ...
- 扩增子分析解读2提取barcode 质控及样品拆分 切除扩增引物
本节课程,需要完成扩增子分析解读1质控 实验设计 双端序列合并 先看一下扩增子分析的整体流程,从下向上逐层分析 分析前准备 # 进入工作目录 cd example_PE250 上一节回顾:我们拿到了双 ...