Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/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
解题思路:构造,给你n和s表示你需要构造的数字的位数合个位数字相加的和,你需要找到满足条件的最大和最小值。最小值,从最后一位开始放数字,直到放不了,当然首位不能为零。最大值,从头开始放,没什么要注意的- -。
1 #include <stdio.h>
2 #include <iostream>
3 #include <string.h>
4 #include <stdlib.h>
5
6 const int maxn = ;
7
8 int a[maxn], b[maxn], m, s;
9
void solve(){
int cnt1, cnt2, temp1, temp2;
int i;
//特判
if(m == && s == ){
printf("0 0\n"); return ;
}
//无法构造的情况
if(s > m * || (m > && s == )){
printf("-1 -1\n"); return ;
}
memset(a, , sizeof(a));
memset(b, , sizeof(b));
temp1 = s; cnt1 = ;
a[m - ] = ; temp1--;
for(i = ; i < m - ; i++){
a[i] = ;
}
while(temp1 > ){
a[cnt1++] = ;
temp1 -= ;
}
if(temp1 > ){
a[cnt1] = a[cnt1] + temp1;
cnt1++;
}
temp2 = s; cnt2 = ;
while(temp2 > ){
b[cnt2++] = ;
temp2 -= ;
}
if(temp2 > ){
b[cnt2++] = temp2;
}
while(cnt2 < m){
b[cnt2++] = ;
}
for(i = m - ; i >= ; i--){
printf("%d", a[i]);
}
printf(" ");
for(i = ; i < cnt2; i++){
printf("%d", b[i]);
}
printf("\n");
}
int main(){
while(scanf("%d %d", &m, &s) != EOF){
solve();
}
return ;
62 }
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...
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- 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< ...
随机推荐
- opensns入门
1.公共控制器 AdminController.class.php 2.控制器中 使用 $list = $this->lists(); 可以获取数据表中的数据,相当于基本的查询 3.将数据查询 ...
- Lightoj1028 【数学-乘法原理】
题意: 给你一个数,问你有多少种进制对n的表示,存在后导零: 比如30:用3进制表示: 1010 思路: 我们发现,就是一个数的约数就能对n表示最后存在后导零: 计算[2 ,n]之间的n的约数个数. ...
- unity语言本地化插件 I2 Location2.5.6使用简单记录
插件下载地址: http://download.csdn.net/detail/onafioo/9579937 1 将插件Resources下的I2Languages.prefab拖到工程里 2 新建 ...
- C#异步调用的应用实践浅谈
C#异步调用的应用实践最经公司工作需要调用一个外部的webservice,同时要将传出的数据进行保存,以自己以前的习惯,就打算逐步操作,失败啊,完全没考虑过用户体验效果,在同事指点下,意识到使用C#异 ...
- Node.js 内置模块fs(文件系统)
fs模块的三个常用方法 1.fs.readFile() -- 读文件 2.fs.writeFile() -- 写文件 3.fa.stat() -- 查看文件信息 fs模块不同于其它模块的地方是它有异步 ...
- IT兄弟连 JavaWeb教程 Servlet会话跟踪 Cookie路径问题
操作Cookie时,需要注意路径问题: 设置操作:任何路径都可以设置Cookie,但是有时我们也是用设置进行替换Cookie和删除Cookie(maxAge=0)! 替换:只能由完全相同的路径来操作! ...
- mysql之SQL入门与提升(三)
今天继续讲mysql数据库 先创建一张Persons表 CREATE TABLE Persons(P_Id int NOT NULL,LastName varchar(255) NOT NULL,Fi ...
- JQuery Easyui/TopJUI 多表头创建
JQuery Easyui/TopJUI 多表头创建 废话不多说,直接贴上代码. html <div data-toggle="topjui-layout" data-opt ...
- A - Beautiful numbers
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- SSIS Passing Parameters to an ADO .NET Source query;向ado.net数据源传递参数。
使用SSIS的oledb数据源时的参数按钮如下图: 但是在使用ADO.NET源连接到MYSQL时,没有这个参数按钮,如何向数据流的sql command传递参数呢? steps: 1. 在 控制流 选 ...