HDU 1260 Tickets (动态规划)
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12331 Accepted Submission(s): 6096
Problem Description
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.
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
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
Sample Output
:: am
:: am
题目大意与分析
有k个人,给出他们买自己的票各自需要多少时间,以及相邻两个人一块买需要多少时间,求从八点开始买,最快什么时候能卖完
状态转移方程:
dp[i]=min(dp[i-1]+a1[i],dp[i-2]+a2[i-1]);
需要注意的是,前补零的写法:%02d
#include<bits/stdc++.h> using namespace std; int dp[],a1[],a2[],i,n,k,times,h,m,s; int main()
{
cin>>n;
while(n--)
{
cin>>k;
for(i=;i<=k;i++)
{
cin>>a1[i];
}
for(i=;i<=k-;i++)
{
cin>>a2[i];
}
dp[]=a1[];
dp[]=;
for(i=;i<=k;i++)
{
dp[i]=min(dp[i-]+a1[i],dp[i-]+a2[i-]);
}
times=dp[k];
s=times%;
m=(times%)/;
h=+times/;
if(h<)
printf("%02d:%02d:%02d am\n",h,m,s);
else
printf("%02d:%02d:%02d pm\n",h-,m,s);
}
}
HDU 1260 Tickets (动态规划)的更多相关文章
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- HDU 1260 Tickets (普通dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others) ...
- 题解报告:hdu 1260 Tickets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...
- HDU 1260 Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...
- 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 (动规)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 1260 Tickets(基础dp)
一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...
随机推荐
- gulp 使用指南
只放一个链接是不是太不负责任 https://gulpjs.com/ https://blog.csdn.net/guang_s/article/details/84664769 gulp安装过程在此 ...
- 灰度图像--图像增强 双边滤波 Bilateral Filtering
学习DIP第31天 转载请标明本文出处:http://blog.csdn.net/tonyshengtan,欢迎大家转载,发现博客被某些论坛转载后,图像无法正常显示,无法正常表达本人观点,对此表示很不 ...
- HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...
- 进程间通信之管道--pipe和fifo使用
匿名管道pipe 函数原型: #include <unistd.h> int pipe(int fildes[2]); 参数说明 fildes是我们传入的数组,也是一个传出参数.filde ...
- AtCoder AGC014E Blue and Red Tree (启发式合并)
题目链接 https://atcoder.jp/contests/agc014/tasks/agc014_e 题解 完了考场上树剖做法都没想到是不是可以退役了... 首先有一个巨难写的据说是\(O(n ...
- [洛谷P3941]:入阵曲(前缀和+桶)
题目传送门 题目背景 丹青千秋酿,一醉解愁肠.无悔少年枉,只愿壮志狂. 题目描述 小$F$很喜欢数学,但是到了高中以后数学总是考不好.有一天,他在数学课上发起了呆:他想起了过去的一年.一年前,当他初识 ...
- [JZOJ5400]:Repulsed(贪心+树形DP)
题目描述 小$w$心里的火焰就要被熄灭了. 简便起见,假设小$w$的内心是一棵$n-1$条边,$n$个节点的树. 现在你要在每个节点里放一些个灭火器,每个节点可以放任意多个. 接下来每个节点都要被分配 ...
- -webkit-scrollbar 的使用,滚动条的隐藏
滚动条的隐藏 -webkit-scrollbar 是一个伪类选择器 设置滚动条的样式 例如滚动条的隐藏 元素::-webkit-scrollbar{ width:0; }
- [Java]一段尚未雕琢的分词代码
package com.hy; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStrea ...
- 域名到IP 报错socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Python中如何通过域名,查看对应的IP? 请看如下代码: import socket hostname="www.baidu.com" ip = socket.gethostb ...