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< ...
随机推荐
- 一步一步学Entity FrameWork 4(1)
http://www.cnblogs.com/qouoww/archive/2012/04/26/2471638.html http://www.cnblogs.com/qouoww/archive/ ...
- Lightoj1084【DP啊DP】
题意: 给你n个人的位置,每个人最多移动k个单位,然后在某点>=3人可以抱团,问你这n个人最少抱团数,只要有一个n不能抱团输出-1: 思路: 感觉又是超级超级狗血.... 剪不断,理还乱... ...
- WindApi2 , WindOriginalApiLibrary 突然不兼容问题
1. 在新的电脑上从tfs拉下代码后编译, windoriginalapilibrary 这个工程弹出对话框,要求转为vs2013编译,选择同意,编译成功 2.WindApi2 的Reference列 ...
- css 三种引用方式
内联式 代码 <!doctype html> <html lang="en"> <head> <meta charset="UT ...
- ADO学途 two day
代码实现的参照性在学习程序中占了关键比重,最基本的都一直无法运行成功,那就无法深入 研究.实现winfrom功能的要点之一实践中获取原理:不清楚代码的一些原理,即使copy过来,大多也 存无法运行的情 ...
- extern用法详解(转)
1 基本解释 extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义. 另外,extern也可用来进行链接指定. 2 问题:ext ...
- Codeforces 1142C(转化、凸包)
可以变换坐标:x' = x, y' = y - x ^ 2,如此之后可得线性函数x' * b + c = y',可以发现两点连边为抛物线,而其他点都在这条线下方才满足题意,故而求一个上凸壳即可. #i ...
- Hibernate-Session使用的背后
一.Session缓存的介绍 简单说,缓存介于应用程序和数据库之间,是临时存放数据的内存区域,作用是减少对数据库的访问次数,从而提高应用程序的运行性能.Session有一个缓存,也叫hibernate ...
- Codeigniter CI 框架的一些优化思考
前段时间使用CI做了两个小项目,对CI的流程和设计理念也有了一些新的认识.CI架构的一些基本优化这里就不做介绍了,如搬离system 文件夹等. 最近有一个稍微大一点的系统,也准备拿CI来做.设计时遇 ...
- js js弹出框、对话框、提示框、弹窗总结
js弹出框.对话框.提示框.弹窗总结 一.JS的三种最常见的对话框 //====================== JS最常用三种弹出对话框 ======================== //弹 ...