zoukankan      html  css  js  c++  java
  • (寒假CF) 比赛要

    题意:给位数和位数和 求符合要求的最大值和最小值

    //想法都有了,可是却没有做粗来(你484傻啊⁽⁽ ◟(눈_눈)◞ ⁾⁾)

    Description

    You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

    Input

    The single line of the input contains a pair of integers ms (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

    Output

    In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).

    Sample Input

    Input
    2 15
    Output
    69 96
    Input
    3 0
    Output
    -1 -1
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int m,s,s1,s2,i;
     8     int a[101],b[101];
     9     while(~scanf("%d %d",&m,&s))
    10     {
    11         int sum=0;
    12         if(m==1&&s==0)
    13         puts("0 0");
    14         else if(s>9*m||s==0)
    15         puts("-1 -1");
    16         else
    17         {
    18             s1=s2=s;
    19             for(i=m-1;i>=1;i--)
    20             {
    21                 if(s1>9)
    22                 {
    23                     a[i]=9;
    24                     s1-=9;
    25                 }
    26                 else if(s1>1)
    27                 {
    28                     a[i]=s1-1;
    29                     s1=1;
    30                 }
    31                 else if(s1==1)
    32                     a[i]=0;
    33             }
    34             a[0]=s1;
    35             for(i=0;i<m;i++)
    36             {
    37                 if(s2>9)
    38                 {
    39                     b[i]=9;
    40                     s2-=9;
    41                 }
    42                 else if(s2>0)
    43                 {
    44                     b[i]=s2;
    45                     s2=0;
    46                 }
    47                 else if(s2==0)
    48                     b[i]=0;    
    49             }
    50             for(i=0;i<m;i++)
    51             printf("%d",a[i]);
    52             printf(" ");
    53             for(i=0;i<m;i++)
    54             printf("%d",b[i]);
    55             printf("
    ");
    56         }
    57     }
    58     return 0;
    59 }


  • 相关阅读:
    acdream.18.KIDx's Triangle(数学推导)
    upc.2219: A^X mod P(打表 && 超越快速幂(in some ways))
    山东省第四届acm.Rescue The Princess(数学推导)
    BC.5200.Trees(dp)
    BC.36.Gunner(hash)
    hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)
    数组倒置算法扩展
    C# 传值和传引用 ( ref out in )
    C# 输出文件夹下的所有文件
    控制反转(自译)
  • 原文地址:https://www.cnblogs.com/awsent/p/4284711.html
Copyright © 2011-2022 走看看