其他分享
首页 > 其他分享> > HDU 1260 Tickets

HDU 1260 Tickets

作者:互联网

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260

分析:先算一下数据范围最多50000s,所以不超过当天晚上12点;

dp相当水,从前往后决策

dp[i] = min(dp[i - 1] + s[i], dp[i  - 2] + d[i])

 1 #include<iostream>
 2 #include<sstream>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<string>
 6 #include<cstring>
 7 #include<algorithm>
 8 #include<functional>
 9 #include<iomanip>
10 #include<numeric>
11 #include<cmath>
12 #include<queue>
13 #include<vector>
14 #include<set>
15 #include<cctype>
16 #define PI acos(-1.0)
17 const int INF = 0x3f3f3f3f;
18 const int NINF = -INF - 1;
19 const int maxn = 2e3 + 5;
20 typedef long long ll;
21 using namespace std;
22 int s[maxn], d[maxn];
23 int dp[maxn];
24 int main()
25 {
26     int n;
27     scanf("%d", &n);
28     while (n--)
29     {
30         int k;
31         scanf("%d", &k);
32         for (int i = 0; i <= k; ++i)
33             s[i] = INF, d[i] = INF, dp[i] = 0;
34         for (int i = 1; i <= k; ++i)
35             scanf("%d", &s[i]);
36         for (int i = 2; i <= k; ++i)
37             scanf("%d", &d[i]);
38         dp[1] = s[1];
39         for (int i = 2; i <= k; ++i)
40         {
41             dp[i] = min(dp[i - 1] + s[i], dp[i - 2] + d[i]);
42             //cout << i << ' ' << dp[i] << endl;
43         }
44         int h, m, s;
45         h = 8 + dp[k] / 3600;
46         m = (dp[k] % 3600) / 60;
47         s = (dp[k] % 3600) % 60;
48         printf("%02d:%02d:%02d ", h, m, s);
49         if (h >= 12) printf("pm\n");
50         else printf("am\n");
51     }
52     return 0;
53 }

 

标签:Tickets,HDU,12,const,int,1260,maxn,include,dp
来源: https://www.cnblogs.com/veasky/p/11363853.html