Tickets
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
Source
题目类型:线性DP
算法分析:dp[i]表示前i个人所花费的最小时间,状态转移方程为dp[i] = min (dp[i-1] + aa[i], dp[i-2] + bb[i])。最后规格化输出即可,注意输出时间的格式!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("aaa.txt", "r", stdin) #define CPPFF ifstream cin ("aaa.txt") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e5 + 6666; int dp[maxn], aa[maxn], bb[maxn]; int main() { // CFF; int t; scanf ("%d", &t); while (t--) { int n; scanf ("%d", &n); for (int i = 1; i <= n; i++) scanf ("%d", &aa[i]); for (int i = 2; i <= n; i++) scanf ("%d", &bb[i]); dp[1] = aa[1]; for (int i = 2; i <= n; i++) dp[i] = min (dp[i-1] + aa[i], dp[i-2] + bb[i]); bool is_am = true; int hour = 8 + dp[n] / 3600; hour %= 12; if (hour >= 12) is_am = false; int minu = dp[n] % 3600 / 60; int sec = dp[n] % 3600 % 60; if (hour < 10) printf ("0%d", hour); else printf ("%d", hour); if (minu < 10) printf (":0%d:", minu); else printf (":%d:", minu); if (sec < 10) printf ("0%d", sec); else printf ("%d", sec); if (is_am) puts (" am"); else puts (" pm"); } return 0; } |
- « 上一篇:hdu1176