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 ...
随机推荐
- TOJ 4689: Sawtooth
4689: Sawtooth Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 26 ...
- 【转】UGUI(小地图的实现)与游戏关卡选择的简单实现
http://www.jianshu.com/p/68637029e9df 游戏中小地图的实现(场景用简单Cube组成先搭建如下图场景,真实场景实现方法也是一样) 图1-1小地图效果图 1.创建好场景 ...
- 只显示前几条数据的sql语句写法 七种数据库中Select Top的使用方法
七种数据库中Select Top的使用方法 1. Oracle数据库 SELECT * FROM TABLENAME WHERE ROWNUM <= N 2. Infomix数据库 SELECT ...
- hihoCoder offer 收割练习赛 74B 取球游戏
Observations 存在取球策略使得每个四连通块可以只剩一个球:保证取走一个球后仍然是个四连通块. 定义新的[相邻]关系:两球在同一行中且所在行中二者之间无其他球,或者两球在同一列且所在列中二者 ...
- [usaco dec 15] 卡牌游戏 cardgame [贪心]
题面: 传送门 思路: 这道题官方标准解法是线段树维护一堆奇奇怪怪的东西......我用的是贪心 方法很简单,处理出pre和suf数组,分别代表前i张.后i张牌在最优方案下打出时可以得到的分数,然后两 ...
- Java注解解析-搭建自己的注解处理器(CLASS注解使用篇)
该文章是继Java注解解析-基础+运行时注解(RUNTIME)之后,使用注解处理器处理CLASS注解的文章.通过完整的Demo例子介绍整个注解处理器的搭建流程以及注意事项,你将知道如何去搭建自己的注解 ...
- linux系统初始化——sysinit文件写法详解
sysinit文件写法详解 sysinit文件是linux初始化文件系统时执行的第一个脚本文件.它主要做在各个运行级别中进行初始化工作,包括: 启动交换分区;检查磁盘;设置主机名;检查并挂载文件系统; ...
- cf 487E Tourist
题目大意 给定\(n\)个点\(m\)条边的无向连通图,无重边 每个点有点权 两个操作: 1.单点点权修改 2.询问从x到y的简单路径中,路径经过点的最小值的最小值时多少 (简单路径指经过每一个点至多 ...
- 创建 router 连通 subnet
上一节我们为 Neutron 虚拟路由器配置好了 L3 agent,今天将创建虚拟路由器“router_100_101”,打通 vlan100 和 vlan101. 打开操作菜单 Project -& ...
- 后缀数组基本问题QAQ
以下题目均来自罗穗骞的论文... No.1最长公共前缀 最长公共前缀: 题目: 给定一个字符串,询问某两个后缀的最长公共前缀. 分析: 某两个后缀的最长公共前缀就是区间height最小值,转化为RMQ ...