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. hdu 5199 Gunner

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... #include<algorithm> #include& ...

  2. iOS 各种系统文件目录 临时,缓存,document,lib,归档,序列化

    /** 1:Documents:应用中用户数据可以放在这里,iTunes备份和恢复的时候会包括此目录 2:tmp:存放临时文件,iTunes不会备份和恢复此目录,此目录下文件可能会在应用退出后删除 3 ...

  3. [转]HTTPS那些事(一)HTTPS原理

    [转]HTTPS那些事(一)HTTPS原理 http://www.guokr.com/post/114121/ 楔子谣言粉碎机前些日子发布的<用公共WiFi上网会危害银行账户安全吗?>, ...

  4. 修改ip脚本

    1.打开运行 2.输入CMD 3.在命令提示符下输入: netsh -c interface ip dump > C:\我的网络配置.txt 4.打开您在C:\ 下的"我的网络配置 . ...

  5. 最基础的Hash

    type thash=^node; node=record state:longint; next:thash; end; var a,i:longint; p:thash; hash:..]of t ...

  6. STL学习三:deque容器

    1.Deque简介 deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. deque在接口上和vector非常 ...

  7. 11.2Daily Scrum

    人员 任务分配完成情况 明天任务分配 王皓南 做文件的网页和数据库连接,任务编号771 实现视频上传的功能 申开亮 实现视频浏览的功能,任务编号772 实现视频浏览的功能 王宇杰 后台测试,任务编号7 ...

  8. 【First Missing Positive】cpp

    题目: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2 ...

  9. Windows窗体应用程序(非Console)使用libuv实现简单的异步WEB服务器

    libuv是一个很强大的异步处理框架(严格意义上不能叫框架,其实就是一组异步函数库,当然框架这东西有各种各样的定义和理解_^...),最初的的目的是用于NODEJS的异步处理,不过因为它是一个独立的项 ...

  10. hdu 2853 Assignment KM算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 Last year a terrible earthquake attacked Sichuan ...