HDU 1260: 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.
输入
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.
输出
样例输入
2
2
20 25
40
1
8
样例输出
08:00:40 am
08:00:08 am
分析:
经典DP题目。状态转移方程:dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i])
#include <stdio.h> #include <string.h> int min(int a,int b){return a>b?b:a; } int a[2005],b[2005],dp[2005]; int main(int argc, char *argv[]) {int t,temp,h;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(dp,0,sizeof(dp));int n;scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",&a[i]);for(int i=2;i<=n;++i)scanf("%d",&b[i]);dp[1]=a[1];dp[2]=min(a[1]+a[2],b[2]);for(int i=3;i<=n;++i)dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);temp=dp[n];h=8+temp/3600;printf("%02d:%02d:%02d %cm\n",h>12?h-12:h,temp%3600/60,temp%60,h>12?'p':'a');}return 0; }
View Code
转载于:https://www.cnblogs.com/Rhythm-/p/9322676.html
HDU 1260: Tickets相关推荐
- HDU 1260 Tickets
dp[i]表示到i这个人所用的最少时间 状态转移方程 dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i-1]); 最后转换一下时间就可以了,当小时大于等于12的时候显示pm,其余显 ...
- Tickets HDU - 1260
Tickets HDU - 1260 题意: 著名的宫崎骏动画片<千与千寻>在中传1500报重映,中传学子有幸成为全国第一批观众.动画学院学生会负责给大家发票,所有的中传同学只要把中传首映 ...
- DP - Tickets - HDU - 1260
DP - Tickets - HDU - 1260 题意: 现在有n个人要买电影票,如果知道每个人单独买票花费的时间,还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 输入: T 组 ...
- HDUOJ 1260 Tickets
HDUOJ 1260 Tickets 题目链接 Problem Description Jesus, what a great movie! Thousands of people are rushi ...
- kuangbin带你飞专题合集
题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...
- 算法学习经典例题整理
陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...
- [kuangbin]专题12 基础DP
HDU 1024 Max Sum Plus Plus HDU 1029 Ignatius and the Princess IV HDU 1069 Monkey and Banana HDU 1074 ...
- 杭电OJ分类题目(2)
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...
- kuangbin带你飞 专题1-23 题单
kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...
- 寒假练习题解 第二周 1.25-1.31
每日一练 1.25 Problem A Luxurious Houses 题意:给 n 个数 a[i],问使得 a[i] 为 [i,n] 最大值的时候需要给 a[i] 增加多少 简析:可以倒着扫一遍, ...
最新文章
- GridView使用常见的注意点
- ArcGIS 坐标系统文件
- CV:利用cv2自带两步法haarcascade_frontalface_default.xml、_smile.xml实现对人脸、笑脸同时检测
- 【知识星球】LeNet5,AlexNet,VGG,MobileNet它们的前身都是什么,你知道吗?
- System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
- vue 事件调用 传参_对vue下点击事件传参和不传参的区别详解
- 客户端 获取服务器性能,客户端数量 服务器性能
- 如何建立双机热备系统
- 前端学习(2838):swiper等比
- Canvas学习:封装Canvas绘制基本图形API
- javascript表格可以输入数据_最火8套测量自动计算表格,输入数据直接得结果,效率提升80%...
- NT下如何彻底删除Oracle?
- paip.PHP-asp—jsp实现事件机制 WEBFORM式开发
- 2021-05-15 MySql面试题 通用篇
- 绕过apple id的那些事
- Redis由于目标计算机积极拒绝,无法连接。
- Python-100-Days学习笔记day11
- 01 APP被苹果APPStore拒绝的各种原因
- 前端项目添加自定义icont图标步骤
- 【JQuery】动画