codeforces#277.5 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
#include<cstdio>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
int m,s;
int main()
{
while(~scanf("%d%d",&m,&s))
{
if((s<1&&m>1)||s>m*9)
{
cout<<-1<<" "<<-1<<endl;
continue;
} for(int i=m-1,k=s;i>=0;i--)
{
int j=max(0,k-9*i);
if(j==0&&i==m-1&&k) j=1;//k!=0非常关键。当数据为1 0时,若k=0则此时要输出0
cout<<j;
k-=j;
}
cout<<" ";
for(int i=m-1,k=s;i>=0;i--)
{
int j=min(9,k);
cout<<j;
k-=j; } }
return 0;
}
codeforces#277.5 C. Given Length and Sum of Digits的更多相关文章
- CF 277.5 C.Given Length and Sum of Digits.. 构造
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- 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)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 ...
- CodeForces 489C Given Length and Sum of Digits... (贪心)
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...
- CodeForces 489C Given Length and Sum of Digits... (dfs)
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- B - Given Length and Sum of Digits... CodeForces - 489C (贪心)
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ...
- codeforces 489C.Given Length and Sum of Digits... 解题报告
题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数.满足长度都为 m,每一位的数字之和等于 s. ...
- CodeForces 489C (贪心) Given Length and Sum of Digits...
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...
- Codeforces 489C Given Length and Sum of Digits...
m位长度,S为各位的和 利用贪心的思想逐位判断过去即可 详细的注释已经在代码里啦~ //#pragma comment(linker, "/STACK:16777216") //f ...
随机推荐
- Hibernate检索策略与检索方式
hibernate的Session在加载Java对象时,一般都会把鱼这个对象相关联的其他Java对象也都加载到缓存中,以方便程序的调用.但很多情况下,我们不需要加载太多无用的对象到缓存中,一来会占用大 ...
- python中的map、reduce、filter、sorted函数
map.reduce.filter.sorted函数,这些函数都支持函数作为参数. map函数 map() 函数语法:map(function, iterable, ...) function -- ...
- django使用haystack对接Elasticsearch实现商品搜索
# 原创,转载请留言联系 前言: 在做一个商城项目的时候,需要实现商品搜索功能. 说到搜索,第一时间想到的是数据库的 select * from tb_sku where name like %苹果手 ...
- 关于springMVC转换json出现的异常
jackson-core-asl-1.9.0.jar,jackson-mapper-asl-1.9.0.jar两个包 并且在controller中有如下代码 @RequestMapping(value ...
- Elasticsearch( 插件开发)
elasticsearch5.2.2 插件开发(一) Scripting plugins:这个插件本质来说,就是会调用用户的脚本,所以可以执行任何的程序,举例的话,可以通过这个插件,支持javascr ...
- 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记4——Direct3D编程基础
第11章 Direct3D编程基础 2D游戏是贴图的艺术,3D游戏是渲染的艺术.这句话在我学过了之前的GDI编程之后,前一句算是有所体会,现在是来理解后一句的时候了. 安装DirectX SDK配置啥 ...
- 都是干货---真正的了解scrapy框架
去重规则 在爬虫应用中,我们可以在request对象中设置参数dont_filter = True 来阻止去重.而scrapy框架中是默认去重的,那内部是如何去重的. from scrapy.dupe ...
- 何時需要重启 OFBiz
你在做如下更改時需要重新启動OFBiz服務器: - Java文件(記得要重新編譯) - 配置/.properties文件 - entitymodel或entitygroup XML定義文件 - 服務或 ...
- KMS使用CLion作为IDE来调试
KMS使用CLion作为IDE来调试,打开kms相应模块的目录,CLion自动识别相应的CMakeLists.txt. 然而会make失败,经搜索,看到Clion使用的自带的cmake,因此系统中安装 ...
- CodeForces 733D Kostya the Sculptor
排序.把每一个长方体拆成$6$个做,然后排序做即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...