Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
1 second
256 megabytes
standard input
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.
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.
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).
2 15
69 96
3 0
-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...的更多相关文章
- 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 ...
- Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489 Problems # Name A SwapSort standard input/output 1 s, 256 ...
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #277.5 (Div. 2)-D
题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...
随机推荐
- struts2使用拦截器完成登陆显示用户信息操作和Struts2的国际化
其实学习框架,就是为了可以很好的很快的完成我们的需求,而学习struts2只是为了替代之前用的servlet这一层,框架使开发更加简单,所以作为一个小菜鸟,特别感谢那些超级无敌变态开发的框架供我们使用 ...
- elastalert邮件报警
https://www.cnblogs.com/zhaijunming5/p/7943933.html
- asp.net core配置访问地址
配置Kestrel Urls有四种方式,我这里只介绍一种.其它方式可自行百度. 在Program.cs里使用UseUrls()扩展方法进行设置.UseUrls()方法的参数是个字符串数组,可以同时设置 ...
- Codeforces 269C Flawed Flow (看题解)
我好菜啊啊啊.. 循环以下操作 1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向. 2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...
- HTML页面滚动时获取离页面顶部的距离2种实现方法
获取离滚动页面的顶部距离有两种方法一是DOM:而是jquery,具体的实现如下,感兴趣的朋友可以尝试操作下 方法一:DOM 复制代码 代码如下: <script> window.o ...
- P1865 A % B Problem 素数筛
题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Cros ...
- 项目的整体框架,以及Topology的设计
一:说明 1.项目的整体框架 2.Topology的设计 3.记录 0. 89.201.10.122 - - [1528033390201] "GET /edit.php HTTP/1.1& ...
- Unity3D 中的面向对象设计 {游戏对象(创建、删除、获取),以及添加修改组件}
一.创建游戏对象 游戏对象分三种:(1) 将物体模型等资源由Project工程面板拖拽到Hierarchy层次面板中 (2) 由GameObject菜单创建Unity自带的游戏对象,如Cube.Cam ...
- cookie、sesion
关于保存问题 如果高并发不多的话可以保存session 否则用cookie吧,session可以保存到其他服务器哦,比如其他服务器的redis memacache(没有持久化,崩了登录信息就全没了) ...
- P2399 non hates math
P2399 non hates math将分数化成小数的模拟题,把循环减掉就可以了.1.1(234)*10^4==11234.234*10^1==11.2349999*(1.1(234))==1122 ...