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< ...
随机推荐
- Linux 下安装 MATLAB
MATLAB是美国MathWorks公司出品的商业数学软件,主要用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,是一款优秀而又强大的数学软件. 本文基于 Deepin 1 ...
- Kylin的简介与安装部署
一.Kylin的概述 官方网址:http://kylin.apache.org/cn/ Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop/Spark之上的SQL查询接口及多维分析 ...
- 【前端基础系列】理解GET与POST请求区别
语义区别 GET请求用于获取数据 POST请求用于提交数据 缓存 GET请求能被缓存,以相同的URL再去GET请求会返回304 POST请求不能缓存 数据长度 HTTP协议从未规定过GET/POST请 ...
- Python subprocess方法
import subprocess #subprocess.call("df -h",shell=True,stdout=subprocess.PIPE)#打印到视图,但是不能保存 ...
- HDU3336 Count the string KMP 动态规划
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU3336 题意概括 给T组数据,每组数据给一个长度为n的字符串s.求字符串每个前缀出现的次数和,结果mo ...
- 练习题|MySQL
MySQL主要内容: 1.数据库介绍.类型.特性2.MySQL数据库安装.连接.启动.停止3.表字段类型介绍.主键约束.表创建语句4.常用增删改查语句.分组.聚合5.外键管理.unique字段.表结构 ...
- Word 如何设置空白页不编码,其他页码连续
或许 不是最简单的方法: 先假设 空白页前的那部分为“第一部分”,空白页后的那部分为“第二部分”. 首先插入2个“分节符”, 将第一部分.空白页.第二部分分成三节(记得取消每一节的“链接到前一条页眉 ...
- poj2230 Watchcow【欧拉回路】【输出路径】(遍历所有边的两个方向)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4392 题目大意: 一个图,要将每条边恰好遍历两遍,而且要以不同的方向,还要回到原点. dfs解法 ...
- 【jvm】来自于线上的fullGC分析
系统最近老年代的内存上升的比较快,三到四天会发生一波fullGC.于是开始对GC的情况做一波分析. 线上老年代2.7G,年轻带1.3G老年代上升较快,3天一波fullGC,并且fullGC会把内存回收 ...
- 【RAY TRACING THE REST OF YOUR LIFE 超详解】 光线追踪 3-5 random direction & ONB
Preface 往后看了几章,对这本书有了新的理解 上一篇,我们第一次尝试把MC积分运用到了Lambertian材质中,当然,第一次尝试是失败的,作者发现它的渲染效果和现实有些出入,所以结尾处声明要 ...