Codeforces-489C-Given Length and Sum of Digits...
来源:互联网 发布:淘宝主图优化软件 编辑:程序博客网 时间:2024/06/01 09:31
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.
Input
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.
Output
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).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1
贪心吧,求最小的时候从0开始选,不能有前导0,最大的时候从9开始选
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int main(){ int m,s; int b[110]; while(scanf("%d%d",&m,&s)!=EOF) { memset(b,0,sizeof(b)); if(s==0) { if(m==1) printf("0 0\n"); else printf("-1 -1\n"); continue; } for(int i=0;i<m;i++) { b[m-i-1]=min(s,9); s-=min(s,9); } if(s) { printf("-1 -1\n"); continue; } int k; for(k=0;!b[k];k++); b[0]++; b[k]--; for(int i=0;i<m;i++) printf("%d",b[i]); printf(" "); b[0]--; b[k]++; for(int i=m-1;i>=0;i--) printf("%d",b[i]); printf("\n"); } return 0;}
- 【Codeforces】 489C Given Length and Sum of Digits
- CodeForces 489C Given Length and Sum of Digits...
- Codeforces 489C Given Length and Sum of Digits
- CodeForces-489C Given Length and Sum of Digits...
- Codeforces-489C-Given Length and Sum of Digits...
- Codeforces 489C. Given Length and Sum of Digits...(greedy)
- codeforces 489C Given Length and Sum of Digits...
- codeforces#277.5 C. Given Length and Sum of Digits
- C. Given Length and Sum of Digits...
- CF 489C Given Length and Sum of Digits... 贪心
- Codeforces 489C - Given Length and Sum of Digits...(贪心)
- 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...
- Codeforces #277.5 (Div. 2) C. Given Length and Sum of Digits...(简单贪心)
- 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...
- Codeforces - 277.5 (Div. 2)C - Given Length and Sum of Digits...(模拟 or dfs)
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- 初识Android
- 如何快速搭建一个服务器
- 各类工具网站推荐
- 【Unity+Vive】第一篇:Vive Input Utility的使用指南
- 迷宫问题——栈的应用
- Codeforces-489C-Given Length and Sum of Digits...
- SVN配置出现svnserve.conf:12错误解决
- synchronized、volatile
- 并查集(disjoint set)的实现及应用
- 1TwoSum
- 向量的基础运算
- MFC----GetDocument()使用
- apple food
- HDU2191-悼念512汶川大地震遇难同胞——珍惜现在,感恩生活