【HDOJ】1260 Tickets

水DP,不过这道题目的数据好像有问题。24时制可表示范围是0~23,12时制可表示范围应为1~12。也就是说24点(即0点)其实表示为12:00:00am,而中午12:00:00其实表示为12:00:00pm,而且从12:00:00~12:59:59都是12:xx:xx pm,而13点开始则应该表示为01:xx:xx pm。题目数据比较小,虽然貌似不考虑这个也可以ac。但是,我个人是按规范做的。

 1 #include <stdio.h>
 2 
 3 #define MAXNUM 2005
 4 
 5 int times[MAXNUM];
 6 int adjacent[MAXNUM];
 7 int dp[MAXNUM];
 8 
 9 int mymin(int a, int b) {
10     return a<b ? a:b;
11 }
12 
13 void test(int *sec, int *min, int *hour) {
14     *sec = 0;
15     *min = 0;
16     *hour = 1;
17 }
18 
19 int main() {
20     int case_n, n;
21     int i, sec, min, hour;
22     char str[3];
23 
24     scanf("%d", &case_n);
25     str[2] = '\0';
26     while (case_n--) {
27         scanf("%d", &n);
28         for (i=1; i<=n; ++i)
29             scanf("%d", &times[i]);
30         for (i=1; i<n; ++i)
31             scanf("%d", &adjacent[i]);
32         dp[0] = 0;
33         dp[1] = times[1];
34         for (i=2; i<=n; ++i)
35             dp[i] = mymin(dp[i-1]+times[i], dp[i-2]+adjacent[i-1]);
36 
37         sec = dp[n];
38         hour = 8;
39         min = sec / 60; sec = sec % 60;
40         hour += min / 60; min = min%60;
41         //test(&sec, &min, &hour);
42         if (hour >= 24)
43             hour = hour%24;
44         if (hour>=12) {
45             if (hour > 12)
46                 hour -= 12;
47             printf("%02d:%02d:%02d pm\n", hour, min, sec);
48         } else {
49             if (hour == 0)
50                 hour = 12;
51             printf("%02d:%02d:%02d am\n", hour, min, sec);
52         }
53     }
54 
55     return 0;
56 }

 

posted on 2014-03-23 22:52  Bombe  阅读(162)  评论(0编辑  收藏  举报

导航