H-tickets
Time limit:1000ms Memory limit:32768kb 64bit IO format:%i64d &%i64u
Submit Status Practice HDU 1260
Description
Jesus, what a great movie! Thousands of people is rushing to the cinema. However, the 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, are let adjacent people buy tickets together. As the restriction of the Ticket Seller machine, Joe can sell a single Ticket or both adjacent tickets at a time.
Since you is the great JESUS, you know exactly what much time needed for every person to buy a single ticket or both ticket s for him/her. Could kind to tell poor Joe at what time Could he go home as early as possible? If So, I guess Joe would full of appreciation for your help.
Input
There is 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 both adjacent people to buy the tickets Togeth Er.
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started he 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[i]: Indicates the minimum time required for a person to buy, transferred to Dp[i]=min (Dp[i-1]+s[i], dp[i-2]+d[i]); The minimum time spent buying tickets with the first two people
#include <bits/stdc++.h>using namespace Std;template<class t>inline T Read (t&x) {char C; while ((C=getchar ()) <=32) if (c==eof) return 0; BOOL Ok=false; if (c== '-') Ok=true,c=getchar (); for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 '; if (OK) x=-x; return 1;} Template<class t> inline T read_ (t&x,t&y) {return read (x) &&read (y);} Template<class t> inline T read__ (t&x,t&y,t&z) {return read (x) &&read (y) &&read (z);} Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x; if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');} Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} -------ZCC IO template------const int MAXN=1E5+1000;CONST double inf=999999999; #define Lson (rt<<1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,t,n) for (int i= (t);i< (n); i++) typedef long Long LL; typedef double DB;TYPEDEF PAir<int,int> P; #define BUG printf ("---\ n"), #define MOD 100007int dp[maxn];//I personally buy tickets required minimum time int s[maxn];int D[MAXN] ; int main () {int n,e,f; Read (n); while (n--) {int k; Read (k); for (int i=1;i<=k;i++) read (s[i]); for (int i=2;i<=k;i++) read (D[i]); Memset (Dp,0,sizeof (DP)); DP[1]=S[1]; for (int i=2;i<=k;i++) {dp[i]=min (dp[i-1]+s[i],dp[i-2]+d[i]); } int m=dp[k]/60; int h=m/60; int ss=dp[k]%60; m%=60; h+=8; if (h<=12) printf ("%02d:%02d:%02d am\n", H,M,SS); else printf ("%02d:%02d:%02d pm\n", H-12,M,SS); } return 0;}
H-tickets HDU 1260 (Dynamic planning)