HOJ---11525 Matchsticks

Matchsticks
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 174, Accepted users: 142
Problem 11525 : No special judgement
Problem description
Matchsticks are ideal tools to represent numbers. A common way to represent the ten decimal digits with matchsticks is the following:


  This is identical to how numbers are displayed on an ordinary alarm clock. With a given number of matchsticks you can generate a wide range of numbers. We are wondering what the smallest and largest numbers are that can be created by using all your matchsticks.

Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:
  • One line with an integer n (2 ≤ n ≤ 100): the number of matchsticks you have


Output
Per testcase:

  • One line with the smallest and largest numbers you can create, separated by a single space. Both numbers should be positive and contain no leading zeroes.


Sample Input
4
3
6
7
15
Sample Output
7 7
6 111
8 711
108 7111111
Problem Source
The 2008 ACM Northwestern Europe Programming Contest

 

 

 

 

水题,深刻的回忆,不解释。

code:

 1 #include<stdio.h>          
 2 int num[7]={10,18,20,20,28,68,88};
 3 __int64 minnumber[100]={0,0,1,7,4,2,6,8,10,18,22,20,28,68,88,108,188,200};
 4 int main() 
 5 { 
 6     int n;
 7     int k;
 8     int i;
 9     int temp;
10     int t;
11     scanf("%d",&n);
12     while(n--)
13     {
14         scanf("%d",&k);
15         if(k<=17)
16             printf("%I64d",minnumber[k]);
17         else
18         {
19             for(i=18;i<=k;i++)
20             {
21                 minnumber[i]=minnumber[i-7]*10+8;
22             }
23             printf("%I64d",minnumber[k]);
24         }
25         if(k%2)
26         {
27             printf(" 7");
28             for(i=0;i<(k-3)/2;i++)
29                 printf("1");
30         }
31         else
32         {
33             printf(" 1");
34             for(i=0;i<(k-2)/2;i++)
35                 printf("1");
36         }
37         printf("\n");
38     }
39     return 0; 
40 } 

 

 

 

 1 test data:
 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 1111111 
15 108 7111111 
16 188 11111111 
17 228 71111111 
18 208 111111111 
19 288 711111111 
20 688 1111111111 
21 888 7111111111 
22 1088 11111111111 
23 1888 71111111111 
24 2008 111111111111 
25 2088 711111111111 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值