码迷,mamicode.com
首页 > 其他好文 > 详细

【HDOJ】2772 Matchsticks

时间:2014-12-25 01:23:12      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:

纯粹的找规律题。
1: 2
2: 5
3: 5
4: 4
5: 5
6: 6
7: 3
8: 7
9: 6
0: 6

2     1     1
3     7     7
4     4    11
5     2     71
6     6     111
7     8     711
8     10     1111
9     18     7111
10     22    11111
11     20    71111
12     28    111111
13     68    711111
14     88
15     108
16     188
17     200
18     208
19     288
20     688
21     888
22     1088

 1 /* 2772 */
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 
 6 int a[15] = {0, 0, 1, 7, 4, 2, 6, 8, 10, 18, 22, 20, 28, 68, 88};
 7 int b[7] = {888, 108, 188, 200, 208, 288, 688};
 8 
 9 int main() {
10     int t, n;
11     int i, j, k;
12     
13     #ifndef ONLINE_JUDGE
14         freopen("data.in", "r", stdin);
15         freopen("data.out", "w", stdout);
16     #endif
17     
18     scanf("%d", &t);
19     while (t--) {
20         scanf("%d", &n);
21         // print min
22         if (n < 15) {
23             printf("%d", a[n]);
24         } else {
25             i = n % 7;
26             printf("%d", b[i]);
27             j = (n-15)/7;
28             while (j--)
29                 printf("8");
30         }
31         // print max
32         i = n & 1;
33         if (i == 0)
34             printf(" 1");
35         else
36             printf(" 7");
37         j = (n-2)/2;
38         while (j--)
39             printf("1");
40         printf("\n");
41     }
42     
43     return 0;
44 }

 

【HDOJ】2772 Matchsticks

标签:

原文地址:http://www.cnblogs.com/bombe1013/p/4183715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!