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
m, s (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

贪心,考虑最大的时候把数组赋值为9,考虑最小的时候把数组第一位赋值1。其它为赋值0

#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int s1[110], s2[110]; int main()
{
int m, s;
while (~scanf("%d%d", &m, &s))
{
if (s == 0 && m == 1)
{
printf("0 0\n");
continue;
}
if (m * 9 < s || s < 1) //每一位全是9都小于s,或者1.....0大于s
{
printf("-1 -1\n");
continue;
}
for (int i = 1; i <= m; ++i)
{
s1[i] = 0;
s2[i] = 9;
}
s1[1] = 1;
int dis = s - 1, cnt = m;
while (1)
{
if (9 - s1[cnt] >= dis)
{
s1[cnt] += dis;
break;
}
dis -= (9 - s1[cnt]);
s1[cnt] = 9;
cnt--;
}
for (int i = 1; i <= m; ++i)
{
printf("%d", s1[i]);
}
printf(" ");
dis = m * 9 - s;
cnt = m;
while (1)
{
if (s2[cnt] >= dis)
{
s2[cnt] -= dis;
break;
}
dis -= (s2[cnt]);
s2[cnt] = 0;
cnt--;
}
for (int i = 1; i <= m; ++i)
{
printf("%d", s2[i]);
}
printf("\n");
}
return 0;
}

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...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  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. [转] ES6 import/export:模块导入导出方式

    export导出语法 // default exports export default 42; export default {}; export default []; export defaul ...

  2. 天天爱跑步&&弹球

    题解: 弹球题目地址:https://www.nowcoder.com/acm/contest/113/E 后面这题 应该是天天爱跑步的加强版本 原理都是查询子树中dep[x]+f[x]的值的个数 由 ...

  3. [NOI2012]骑行川藏(未完成)

    题解: 满分又是拉格朗日啥的 以后再学 自己对于n=2猜了个三分 然后对拍了一下发现是对的

  4. Codeforces Round #395 (Div. 2)

    今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内  两个序列  n,2*n,3*n...... ...

  5. width:100vh与min-height:calc(100vh + 51px)

    vh:相对于视窗的高度,那么vw:则是相对于视窗的高度. “视区”所指为浏览器内部的可视区域大小,即window.innerWidth/window.innerHeight大小,不包含任务栏标题栏以及 ...

  6. BZOJ3211 花神游历各国 并查集 树状数组

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3211 题意概括 有n个数形成一个序列. m次操作. 有两种,分别是: 1. 区间开根(取整) 2. ...

  7. C#介绍

    1.c#与.net框架 c#属于.net框架的一个子集. 2..net框架 3.BCL 基类库 4.编译过程 5.运行过程 6.总结 7.CLR

  8. ubuntu 18图形界面

    sh .start_mode.sh: 换操作方式(图形界面,终端界面): 桌面版: 界面中 ctrl + shift + t 打开终端 ctrl + shift + "+" 放大字 ...

  9. POJ 1279 Art Gallery【半平面交】(求多边形的核)(模板题)

    <题目链接> 题目大意: 按顺时针顺序给出一个N边形,求N边形的核的面积. (多边形的核:它是平面简单多边形的核是该多边形内部的一个点集该点集中任意一点与多边形边界上一点的连线都处于这个多 ...

  10. [洛谷P3014][USACO11FEB]牛线Cow Line (康托展开)(数论)

    如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行 ...