zoukankan      html  css  js  c++  java
  • HOJ11525 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 
  • 相关阅读:
    解决Original error: Could not proxy command to remote server. Original error: Error: socket hang up
    python各进制转换
    爬楼梯问题,yield学习总结
    微信开放平台API开发资料
    数据切分——Atlas读写分离Mysql集群的搭建
    svn SSL 错误:Key usage violation in certificate has been detected
    如何将一个空间里的内容全部复制到另一个空间,文件名不变
    SVN客户端安装 Linux
    Web端即时通讯技术盘点:短轮询、Comet、Websocket、SSE
    搭建SVN服务器
  • 原文地址:https://www.cnblogs.com/XBWer/p/2614274.html
Copyright © 2011-2022 走看看