http://codeforces.com/problemset/problem/489/C

C. Given Length and Sum of Digits...
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
input
2 15
output
69 96
input
3 0
output
-1 -1

解题思路:构造,给你n和s表示你需要构造的数字的位数合个位数字相加的和,你需要找到满足条件的最大和最小值。最小值,从最后一位开始放数字,直到放不了,当然首位不能为零。最大值,从头开始放,没什么要注意的- -。

 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 
 6 const int maxn = ;
 7 
 8 int a[maxn], b[maxn], m, s;
 9 
 void solve(){
     int cnt1, cnt2, temp1, temp2;
     int i;
     //特判
     if(m ==  && s == ){
         printf("0 0\n"); return ;
     }
     //无法构造的情况
     if(s > m *  || (m >  && s == )){
         printf("-1 -1\n"); return ;
     }
     memset(a, , sizeof(a));
     memset(b, , sizeof(b));
     temp1 = s; cnt1 = ;
     a[m - ] = ; temp1--;
     for(i = ; i < m - ; i++){
         a[i] = ;
     }
     while(temp1 > ){
         a[cnt1++] = ;
         temp1 -= ;
     }
     if(temp1 > ){
         a[cnt1] = a[cnt1] + temp1;
         cnt1++;
     }
     temp2 = s; cnt2 = ;
     while(temp2 > ){
         b[cnt2++] = ;
         temp2 -= ;
     }
     if(temp2 > ){
         b[cnt2++] = temp2;
     }
     while(cnt2 < m){
         b[cnt2++] = ;
     }
     for(i = m - ; i >= ; i--){
         printf("%d", a[i]);
     }
     printf(" ");
     for(i = ; i < cnt2; i++){
         printf("%d", b[i]);
     }
     printf("\n");
 }
 
 int main(){
     while(scanf("%d %d", &m, &s) != EOF){
         solve();
     }
     return ;

62 }

Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...的更多相关文章

  1. Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  2. Codeforces Round #277.5 (Div. 2) ABCDF

    http://codeforces.com/contest/489 Problems     # Name     A SwapSort standard input/output 1 s, 256 ...

  3. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

  4. Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

    http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...

  5. Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being

    http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...

  6. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  7. Codeforces Round #277.5 (Div. 2)-A. SwapSort

    http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...

  8. Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. SwapSort time limit per test    1 seco ...

  9. Codeforces Round #277.5 (Div. 2)-D

    题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...

随机推荐

  1. 《剑指offer面试题4》替换空格——实现函数把字符串中每个空格替换成“%20”

    思路: 例如把we are happy这个字符串中所有空格替换成"%20",最直接的做法是从头开始扫苗,遇到空格就替换,并且把空格后面的字符都顺序后移.复杂度O(n^2). 重要思 ...

  2. python-os.walk()使用举例

    文件目录结构 dir 1 1 1.txt 2.txt 3.txt 2 2.txt 3 4 4.txt 3.txt 1.txt 2 2.txt 3 3.txt dir.txt 代码: import os ...

  3. spring基于注解的IOC

    曾经的XML配置: <bean id="accountService" class="com.itheima.service.impl.AccountService ...

  4. 无法序列化会话状态。请注意,当会话状态模式为“StateServer”或“SQLServer”时,不允许使用无法序列化的对象或 MarshalByRef 对象。

    原文链接:http://blog.csdn.net/byondocean/article/details/7564502 session是工作在你的应用程序进程中的.asp.net进程.iis往往会在 ...

  5. 第二章 "我要点爆"微信小程序点爆页面的实现与云函数和云存储的应用

    点爆页面的实现与云函数和云存储的应用以及录音功能讲解 点爆页面制作 点爆页面主要提供文字记录和语音记录两种爆文记录方式,在本页面内输入文字或录入语音后选择心情点击点爆按钮,跳转到点爆方式选择界面. 首 ...

  6. ADO学途 five day 连接数据库

    用一个程序的目的就是为了方便对数据进行操作,没有数据的支持,程 序就成了一个空壳子.一般我们常用的数据库有三种mysql, SQL server, Oracle. C#中常用的就是SQL server ...

  7. SpringMVC注解校验

    spring注解式参数校验     版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jinzhencs/article/details/5168283 ...

  8. Python-4-设置字符串的格式字符串

    字符串是不可变的,所有元素赋值和切片赋值都是非法的   1.替换字段名 可以按顺序和名称匹配 >>> "{foo} {} {bar} {}".format(1, ...

  9. css-bootstrap

    CSS概览 基本的bootstrap包含三个文件,引入到html页面中 <link href="{% static 'css/bootstrap.min.css' %}" r ...

  10. Metasploits之Adobe阅读器漏洞

    实验环境:Kali 2.0+Windows XP+Adobe Reader 9.3.0 类别:缓冲区溢出 描述:这个漏洞针对Adobe阅读器9.3.4之前的版本,一个名为SING表对象中一个名为uni ...