题目描述

Jesus, 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.

输入

There 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.

输出

For 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
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相关推荐

  1. HDU 1260 Tickets

    dp[i]表示到i这个人所用的最少时间 状态转移方程 dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i-1]); 最后转换一下时间就可以了,当小时大于等于12的时候显示pm,其余显 ...

  2. Tickets HDU - 1260

    Tickets HDU - 1260 题意: 著名的宫崎骏动画片<千与千寻>在中传1500报重映,中传学子有幸成为全国第一批观众.动画学院学生会负责给大家发票,所有的中传同学只要把中传首映 ...

  3. DP - Tickets - HDU - 1260

    DP - Tickets - HDU - 1260 题意: 现在有n个人要买电影票,如果知道每个人单独买票花费的时间,还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 输入: T 组 ...

  4. HDUOJ 1260 Tickets

    HDUOJ 1260 Tickets 题目链接 Problem Description Jesus, what a great movie! Thousands of people are rushi ...

  5. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  6. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  7. [kuangbin]专题12 基础DP

    HDU 1024 Max Sum Plus Plus HDU 1029 Ignatius and the Princess IV HDU 1069 Monkey and Banana HDU 1074 ...

  8. 杭电OJ分类题目(2)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(2) HDU Water~~~ HDU 100 ...

  9. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  10. 寒假练习题解 第二周 1.25-1.31

    每日一练 1.25 Problem A Luxurious Houses 题意:给 n 个数 a[i],问使得 a[i] 为 [i,n] 最大值的时候需要给 a[i] 增加多少 简析:可以倒着扫一遍, ...

最新文章

  1. GridView使用常见的注意点
  2. ArcGIS 坐标系统文件
  3. CV:利用cv2自带两步法haarcascade_frontalface_default.xml、_smile.xml实现对人脸、笑脸同时检测
  4. 【知识星球】LeNet5,AlexNet,VGG,MobileNet它们的前身都是什么,你知道吗?
  5. System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
  6. vue 事件调用 传参_对vue下点击事件传参和不传参的区别详解
  7. 客户端 获取服务器性能,客户端数量 服务器性能
  8. 如何建立双机热备系统
  9. 前端学习(2838):swiper等比
  10. Canvas学习:封装Canvas绘制基本图形API
  11. javascript表格可以输入数据_最火8套测量自动计算表格,输入数据直接得结果,效率提升80%...
  12. NT下如何彻底删除Oracle?
  13. paip.PHP-asp—jsp实现事件机制 WEBFORM式开发
  14. 2021-05-15 MySql面试题 通用篇
  15. 绕过apple id的那些事
  16. Redis由于目标计算机积极拒绝,无法连接。
  17. Python-100-Days学习笔记day11
  18. 01 APP被苹果APPStore拒绝的各种原因
  19. 前端项目添加自定义icont图标步骤
  20. 【JQuery】动画

热门文章

  1. SpringBoot整合RabbitMQ之Fanout Exchange扇形(广播式)交换机(学习总结)
  2. 如何调试一个无法重现的错误?
  3. Spring源码系列 — BeanDefinition
  4. 中国孩子的micro:bit:TurnipBit自制小乐器教程实例
  5. KeyShot中该怎么添加反射地平面
  6. 使用Fresco实现简单的显示一张图片
  7. 导出excel乱码问题
  8. 如何用弹出窗口显示进度 - 回复 嘿嘿嘿 的问题
  9. Java线程并发与安全性问题详解
  10. InputMethodManager内存泄漏的原因及解决方案