Tickets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 711    Accepted Submission(s): 354

Problem Description
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.
 
Input
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.
 
Output
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.
 
Sample Input
2
2
20 25
40
1
8
 
Sample Output
08:00:40 am
08:00:08 am
 

状态转移方程:

dp[0] = 0;

dp[1] = a[1];

dp[i] = min(dp[i-1] + a[i], dp[i-2] + b[i-1]);(i : 1->k)

解题代码:

 1 // File Name: Tickets 1260.cpp
2 // Author: sheng
3 // Created Time: 2013年05月24日 星期五 21时22分20秒
4
5 #include <iostream>
6 #include <stdio.h>
7 #include <string.h>
8 using namespace std;
9
10 const int max_k = 2003;
11
12 int dp[max_k], a[max_k], b[max_k];
13 int min (int a, int b)
14 {
15 return a > b ? b : a;
16 }
17
18 int main ()
19 {
20 int n;
21 int k, MIN;
22 int sec, minute, hour;
23 scanf ("%d", &n);
24 while (n --)
25 {
26 scanf ("%d", &k);
27 for (int i = 1; i <= k; i ++)
28 scanf ("%d", &a[i]);
29 for (int i = 1; i < k; i ++)
30 scanf ("%d", &b[i]);
31 dp[0] = 0;
32 dp[1] = a[1];
33 for (int i = 2; i <= k; i ++)
34 {
35 dp[i] = min(dp[i - 1] + a[i], dp[i - 2] + b[i - 1]);
36 }
37 // printf ("%d\n", dp[k]);
38 minute = dp[k]/60;
39 sec = dp[k]%60;
40 hour = 8 + minute/60;
41 minute %= 60;
42 if (hour > 12)
43 hour -= 12;
44 if (hour < 10)
45 printf ("0");
46 printf ("%d:", hour);
47 if(minute < 10)
48 printf ("0");
49 printf ("%d:", minute);
50 if (sec < 10)
51 printf ("0");
52 printf ("%d", sec);
53 printf (" %s\n", hour <= 12 ? "am" : "pm");
54 }
55 return 0;
56 }

G++

HDU 1260 Tickets(简单dp)的更多相关文章

  1. HDU - 1260 Tickets 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...

  2. 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets

    2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...

  3. HDU 1260 Tickets (普通dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others)   ...

  4. HDU 1260 Tickets DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...

  5. HDU 1260 Tickets(基础dp)

    一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...

  6. 题解报告:hdu 1260 Tickets

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...

  7. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...

  8. POJ 1260 Pearls 简单dp

    1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/a ...

  9. hdoj 1260 Tickets【dp】

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

随机推荐

  1. java中的排序

    排序是数据结构中重要的一个部分,也是在实际开发中最易遇到的问题之一,当然了,你也可以不考虑这些排序的算法,直接把要排序的数据insert到数据库中,用数据库的order by再select一下,也能产 ...

  2. 误删system04.dbf 报:ORA-01157 ORA-01110

    DB:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production OS:Oracle Linux 5.7 ...

  3. hdu 1316 How Many Fibs?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...

  4. Python: 函数参数小结

    参数的类型: 函数的参数有2种类型: 1. 函数定义时用于接收值的形式参数Parameters. 2. 函数调用时用于传递值的实际参数Arguments. 参数的传递: 传递方式有2种: 1. 值传递 ...

  5. JVM学习总结一——内存模型

    JVM是java知识体系的基石之一,任何一个java程序的运行,都要借助于他.或许对于我这种初级程序员而言,工作中很少有必要刻意去关注JVM,然而如果能对这块知识有所了解,就能够更清晰的明白程序的运行 ...

  6. Mysql 更改最大连接数

    方法一: 进入MySQL安装目录 打开MySQL配置文件 my.ini 或 my.cnf查找 max_connections=100 修改为 max_connections=1000 服务里重起MyS ...

  7. [转]Not enough free disk space on disk '/boot'

    Not enough free disk space on disk '/boot' http://my.oschina.net/u/947673/blog/277224 # 解决 出现此情况是因为你 ...

  8. 42.JTAG接口使用注意

    无论是客户反馈,还是自己亲身经历,USB-Blaster不能下载配置FPGA的情况时有出现.究其原因,大致有如下几条: 1. FPGA器件上的JTAG相关引脚出现故障: 2. USB-Blaster坏 ...

  9. Python实现kMeans(k均值聚类)

    Python实现kMeans(k均值聚类) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=> ...

  10. Junit单元测试中优先使用AssertThat

    主要的优点: 1. 易读性 2. 错误信息更方便 推荐阅读:https://objectpartners.com/2013/09/18/the-benefits-of-using-assertthat ...