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 with…
http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a positive integer m and a non-negative integer …
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Description 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…
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the la…
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the la…
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the la…
题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数.满足长度都为 m,每一位的数字之和等于 s.如果构造不出来,输出 -1 -1.否则输出最小和最大且符合条件的数. 想了两个多小时,发现想错了方向...... /****************************************** 首先把不能得到最小数和最大数的情况揪出来. 第二组测试数据 3 0 有提示,s = 0 且 m >…
题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can(int m, int s)函数,来判断是否存在一个m位数其各位数字之和为s 这里先不考虑前导0的事,代码看起来可能是这个样子的: bool can(int m, int s) { && s <= m*); } 比如我们现在要求满足要求的最小整数,从最左边的数开始从0到9开始试,如果后面的…
m位长度,S为各位的和 利用贪心的思想逐位判断过去即可 详细的注释已经在代码里啦~ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring> #include <cmath> #include <stack> #include <queu…
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <t…