Codeforces Round #277.5 (Div. 2)(C题)
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 <iostream>
#include <algorithm>
#include <cstdio>
using namespace std; bool can(int m, int s)
{
if(s >= 0 && 9*m >= s) return true;
else return false;
}
int main()
{
int m,s;
cin>>m>>s;
if(!can(m,s))
{
cout<<"-1"<<" "<<"-1"<<endl;
return 0;
}
if(m == 1)
{
if(s >= 10)
{
cout<<"-1"<<" "<<"-1"<<endl;
}
else cout<<s<<" "<<s<<endl;
}
else {
if(s == 0) cout<<"-1"<<" "<<"-1"<<endl;
else { string minn, maxn;
int sum = s; for(int i = 1; i <= m; i++)
for(int j = 0; j < 10; j++)
{
if((j > 0 || (j == 0 && i > 1) ) && can(m - i, sum - j))
{
minn += char('0' + j);
sum -= j;
break;
}
} sum = s;
for(int i = 1; i <= m; i++)
for(int j = 9; j >= 0; j--)
{
if(can(m - i, sum - j))
{
maxn += char('0' + j);
sum -= j;
break;
}
} cout<<minn<<" "<<maxn<<endl; }
}
return 0;
}
Codeforces Round #277.5 (Div. 2)(C题)的更多相关文章
- 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)B——BerSU Ball
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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)-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)-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 ...
随机推荐
- php 备份数据库代码(生成word,excel,json,xml,sql)
单表备份代码: 复制代码代码如下: <?php class Db { var $conn; function Db($host="localhost",$user=" ...
- WMS请求GetCapabilities,变成下载mapserv.exe解决办法
WMS1.1.1和WMS1.3.0两个版本中的几个区别: 1.WMS1.1.1中提供的DescribeLayers.GetStyles等接口在WMS1.3.0中不再提供支持,只提供GetCapabil ...
- cmake 版本升级
1.在网址 https://cmake.org/files/v3.1/下载 cmake-3.1.0.tar.gz 2.解压 3.执行 ./configure 4.执行 make 5. 执行 ...
- golang深坑记录
go深坑:1.gin.context.JSON,如果没有make数组时,数组返回为null,make后,数组为[]2.json.Number转int64类型 datatemp.(json.Number ...
- jquery取得iframe中元素的方法
原文发布时间为:2010-12-27 -- 来源于本人的百度文章 [由搬家工具导入] 收集利用Jquery取得iframe中元素的几种方法 :contents() $.trim($("if ...
- LeetCode OJ-- LRU Cache ***@
https://oj.leetcode.com/problems/lru-cache/ 涨姿势的一道题,相当于实现一种数据结构,实现最近最少使用数据结构. // 用来记录 前后节点都是什么 类似链表上 ...
- LeetCode OJ-- Populating Next Right Pointers in Each Node
https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/ 二叉树遍历的变种:树的节点多了个next指针 ...
- AC日记——通往奥格瑞玛的道路 洛谷 P1462
通往奥格瑞玛的道路 思路: 二分+spfa: 二分最大费用,然后判断只走小于等于二分答案的点是否可以花费小于体力上限的血量: 来,上代码: #include <cstdio> #inclu ...
- HDU 5727.Necklace-二分图匹配匈牙利
好久没写过博客了,把以前的博客补一下. Necklace Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- Axisfault faultcode:Server.userException异常
---恢复内容开始--- Axisfault faultcode:Server.userException异常 AxisFault faultCode: {http://schemas.xmlsoap ...