HDU 1260 tickets (motion gauge)

Source: Internet
Author: User
Tags integer numbers
Tickets Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 924 accepted submission (s): 468



Problem descriptionjesus, 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 cocould he go back home as early as possible.
A good approach, cing the total time of tickets selling, is let adjacent people buy tickets together. as the restriction of the ticket seller machine, Joe can handle 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. cocould you so kind to tell poor Joe at what time cocould he go back home as early as possible? If so, I guess Joe wocould full of appreciation for your help.
 
Inputthere 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 (0 S <= SI <= 25 s) representing the time consumed to buy a ticket for each person;
(K-1) integer numbers (0 S <= di <= 50 s) representing the time needed for two adjacent people to buy two tickets together.
 
Outputfor every scenario, please tell Joe at what time cocould 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
2220 254018
 
Sample output
08:00:40 am08:00:08 am
 
Source Zhejiang University of Technology's fourth college Program Design Competition
Recommendjgshining | we have carefully selected several similar problems for you: 1074 1114 1264 1024

Solution:

A person can buy a ticket separately for a certain period of time, or two people can buy a ticket together, and a time is also given,

Give K individual separately bought time and K-1 two adjacent two people bought time together, ask the minimum time spent in total.

Map [] indicates the time a person bought separately, and V [] indicates the time when two people bought together.
The decision is to buy them together or separately;

Code: 0 ms
# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm>Using namespaceSTD;# Define M 2050 # define INF 999999IntMap[M],V[M],DP[M]; Int main () {intI,N,M,T,J,K; While (CIN>T) {While (T--){CIN>N; (I=1;I<=N;I++)CIN>Map[I]; // The time when the ticket is bought separately. For (I=1;I<=N-1;I++)CIN>V[I]; // The time when the ticket is bought together. For (I=0;I<=N;I++)DP[I] = (I=0?0:INF);DP[1] =Map[1]; (I=2;I<=N;I++ ){DP[I] =Min(DP[I-1] +Map[I],DP[I-2] +V[I-1]); // Decision. } IntH=DP[N]/3600+8; // Converts the time. IntM=DP[N]/60%60; IntS=DP[N] %60;Printf("% 02d: % 02d: % 02d am \ n",H,M,S); // No two replicas are added to the first zero. } Return0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.