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 ...
随机推荐
- ActionContext和ServletActionContext小结
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- 在控制器“xxxx”上找不到与该请求匹配的操作
Message:"找不到与请求 URI"http://localhost:8091/Api/CommonApi/SelectBind/GetBudCategoryListByCID ...
- jQuery操作DOM基础 - 元素属性的查看与设置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#中的is和as的转型区别
摘自CLR via C#第三版第四章 在c#中is可以用来判断一个对象是否兼容给定的类型,如果是返回true,否则返回false. 同时is是永不会抛出异常的.如果对象引用是null,is操作符总是返 ...
- 习题:过路费(kruskal+并查集+LCA)
过路费 [问题描述]在某个遥远的国家里,有 n 个城市.编号为 1,2,3,…,n.这个国家的政府修 建了 m 条双向道路,每条道路连接着两个城市.政府规定从城市 S 到城市 T 需 要收取的过路费 ...
- Ubuntu安装opencv with cuda
Ubuntu安装opencv with cuda 为了运行dense flow真是折腾啊,下面网址是教程 http://blog.aicry.com/ubuntu-14-04-install-open ...
- 【ZOJ4060】 Flippy Sequence(规律)
题意:给定两个长度为n的01序列A和B,要求分别从两个序列中取两段将段中数字取反,使得A和B完全相同,求方案数 n<=1e6,sum(n)<=1e7 思路:现场8Y…… 将A和B异或之后问 ...
- 【HDOJ5555】Immortality of Frog(状压DP)
题意:给你一个NxN的网格,第N行的每一列都有个青蛙,这些青蛙只会往上走, 上帝会在每个膜中随机等概率放一个长生不老的药, 一共有N个膜,每个膜覆盖一些区间,如果这个区间恰好为N那么就是好膜,否则是坏 ...
- Docker(五):镜像
一,什么是镜像? Docker的镜像文件是由文件系统叠加而成的.最底端是一个引导文件系统,即bootfs.Docker用户几乎永远没有机会和引导文件有什么交互,实际上,当一个容器启动之后,容器就会被移 ...
- 关于 gstreamer 和 webrtc 的结合,有点小突破
今天让我找到了 gstreamer 的一个牛叉的杀手锏,脑海中马上想到了一个大致的框架和方案计划,用 gst-inspector 先进行对象自省属性探测,然后祭出 gst-launcher 大刀进行管 ...