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. Codevs 1018 单词接龙

    1018 单词接龙 2000年NOIP全国联赛普及组NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描 ...

  2. Codevs 3112 二叉树计数

    3112 二叉树计数 题目描述 Description 一个有n个结点的二叉树总共有多少种形态 输入描述 Input Description 读入一个正整数n 输出描述 Output Descript ...

  3. Android NFC P2P

    http://www.nfc.cc/2011/12/28/development-android-beam-and-nfc-peer-2-peer/

  4. shell学习(7)- linux权限管理及修改权限命令chmod

    文件系统权限基本介绍 1.文件基本权限 总共10个字符,可以分为四组, 第一组,就一个字符-,代表是文件类型,是一个常规文件,还有其他的类型如下所示 d--目录 l--符号链接,软连接 c--字符专门 ...

  5. IDEA 快捷键MacOS

    Alt + Enter 导入包,自动修正 Command + N 查找类 Command + Shift + N查找文件 Command + Alt + L格式化代码 Command + Alt + ...

  6. Tinghua Data Mining

    Learning Resources 书籍: 期刊: 业界先驱: 开阔视野,掌握业界最新动态. 工具: 数据挖掘是很多学科的综合体: 甭管叫什么名字,归根到底都是数据挖掘: Comprehensive ...

  7. 多线程:『GCD』详尽总结

    本文用来介绍 iOS 多线程中 GCD 的相关知识以及使用方法.这大概是史上最详细.清晰的关于 GCD 的详细讲解+总结的文章了.通过本文,您将了解到:1. GCD 简介2. GCD 任务和队列3. ...

  8. Codeforces Round #547 (Div. 3) D. Colored Boots

    链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...

  9. 手动释放Linux内存

    查看内存: [root@iZ9dp52tlpqyihuisujjswZ bin]# free -h total used free shared buff/cache available Mem: 3 ...

  10. ubuntu管理apt包的常用命令

    安装 apt-get install nginx #安装 apt-get install nginx --reinstall #重新安装 删除 apt-get remove nginx #卸载 apt ...