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. CSS3 制作魔方 - 玩转魔方

    在上一篇<CSS3 制作魔方 - 形成魔方>中介绍了一个完整魔方的绘制实现,本文将介绍魔方的玩转,支持上下左右每一层独立地旋转.先来一睹玩转的风采. 1.一个问题 由于魔方格的位置与转动的 ...

  2. PhpStorm插件之CodeGlance

    安装插件 File->Setting->Pluugins   搜索  CodeGlance 如何使用 安装完插件后,RESTART IDE,随便打开一个文件都可看到效果

  3. Codeforces691A【读题-水】

    妈蛋wa了两次.. 时尚的定义是length大于1的要破个洞,一定要破个洞.. According to rules of the Berland fashion, a jacket should b ...

  4. VR相关网站

    VR87870 http://www.87870.com/ VR玩家网 http://www.vrwanjia.cn/ VR之家 http://www.vr.cn/ http://gad.qq.com ...

  5. IT兄弟连 JavaWeb教程 EL与JSTL表达式经典面试题

    1.简述EL表达式的作用 EL表达式的作用可分为以下三类 访问Bean的属性. 输出简单的运算结果. 获取请求参数值. 2.JSP标签的作用?如何定义? JSP标签可以分离JSP页面的内容和逻辑,业务 ...

  6. spark sql 对接 HDFS

    上一篇博客我向大家介绍了如何快速地搭建spark run on standalone,下面我将介绍saprk sql 如何对接 hdfs 我们知道,在spark shell 中操作hdfs 上的数据是 ...

  7. web前端篇:JavaScript正则表达式

    目录 JavaScript正则表达式 1.创建正则表达式 1.1方法1:直接量语法 1.2 方法2:创建RegExp对象的语法 1.3 区别: 1.4正则表达式使用 2.正则对象的属性 2.1.属性 ...

  8. 关于Dictionary的优化用法

    今天突然想到了解一下Dictionary,于是在博客园上看到了一篇关于用TryGetValue的文章,原来用TryGetValue要比用ContainsKey更快,快一倍.

  9. springboot2.x 的 RedisCacheManager变化

    springboot2.x 的 RedisCacheManager变化 springboot2.x 的 RedisCacheManager变化 由于最近在学着使用redis做缓存,使用的是spring ...

  10. web.xml中一个filter配置多个url-pattern

    需要在filter标签后添加多个filter-mapping标签,一个url-pattern就对应一个filter-mapping标签,不能直接把多个url-pattern配置到同一个filter-m ...