HDU 1260
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 <bits/stdc++.h>
#define M 2009
using namespace std; int n,k,a[M],t[M],dp[M];
int hh,mm,ss; int main()
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&k);
for(int i = 1; i <= k; i++)
scanf("%d",&a[i]);
for(int i = 2; i <= k; i++)
scanf("%d",&t[i]);
dp[1] = a[1];
for(int i = 2; i <= k; i++)
dp[i] = min(dp[i-1]+a[i],dp[i-2]+t[i]); hh = dp[k]/3600;
mm = (dp[k]%3600)/60;
ss = dp[k]%60; printf("%02d:%02d:%02d %s",( 8 + hh)%24,mm,ss,(8 + hh)%24 > 12 ? "pm\n" : "am\n");
} return 0;
}
HDU 1260的更多相关文章
- 【DP】HDU 1260
HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是 ...
- 怒刷DP之 HDU 1260
Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- Tickets HDU - 1260 水DP
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...
- (dp)Tickets --HDU --1260
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1260 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1260 Tickets (普通dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others) ...
- HDU - 1260 Tickets 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...
- HDU 1260 Tickets DP
http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...
- 题解报告:hdu 1260 Tickets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...
随机推荐
- C语言 sscanf用法详解
/* sscanf用法详解 */ #include <stdio.h> /* sscanf头文件 */ #include <stdlib.h> #include <str ...
- VS IISExpress REST DELETE 405 Method Not Allowed
[参考].net IIS MVC Rest api 跨域 PUT DELETE 404 无法使用问题解决方案 今日在使用泛型處理常式處理檔案上傳時,使用了 HTTP 動詞的 PUT.DELETE 進行 ...
- python定义函数时,形参前加*和**的意义
转发:https://blog.csdn.net/qq_34806812/article/details/82017839 1.加*表示接受一个tuple类型(元组),如: 2.加**表示接受一个di ...
- tensorflow, TypeError:'Tensor' object is not callable
解决办法:两个tensor相乘,需要加“*”.
- laravel5.8笔记三:常用命令
创建控制器 php artisan make:controller Index/IndexController 创建模型 php artisan make:model Index/IndexContr ...
- 超简单C#获取带汉字的字符串真实长度(单个英文长度为1,单个中文长度为2)
https://blog.csdn.net/u014732824/article/details/84952848 int i = System.Text.Encoding.Default.GetBy ...
- 关于Kafka producer管理TCP连接的讨论
在Kafka中,TCP连接的管理交由底层的Selector类(org.apache.kafka.common.network)来维护.Selector类定义了很多数据结构,其中最核心的当属java.n ...
- makefile编译错误情况整理
错误情况1:makefile:5: *** 遗漏分隔符 . 停止 原因:具体的编译动作,开头不可以有空格,留白是由 按tab键形成的. 解决方法:去掉空格,改为tab键后,再执行make命令,成功. ...
- 设置弹窗、遮罩的样式设置(包括:left、heigh等)
.zhezhao { width:100%; background-color:#000; filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0. ...
- php验证18位身份证,准到必须输入正确的身份证号,
/** * 验证18位身份证(计算方式在百度百科有) * @param string $id 身份证 * return boolean */ function check_identity($id=' ...