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 
  • 相关阅读:
    0052 html5多媒体音频标签audio
    0051 HTML5概述、新增标签、简单案例
    0050 VSCode软件
    0048 :focus -- 获得焦点元素
    0046 CSS3过渡:transition
    Linux 中的常见锁及其基本原理
    小程序海报最佳实现思路,可视化编辑直接生成代码使用
    babel插件的相关知识
    vue-next 函数式 api
    小程序如何改变onLoad 的执行时机?
  • 原文地址:https://www.cnblogs.com/XBWer/p/2614274.html
Copyright © 2011-2022 走看看