/*************************************************************************
> File Name: cf.cpp
> Author: acvcla
> QQ:
> Mail: acvcla@gmail.com
> Created Time: 2014年11月17日 星期一 23时34分13秒
************************************************************************/
#include
#include
#include
#include
#include
#include
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 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.
InputThe 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.
OutputIn 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).
Sample test(s) input2 15output
69 96input
3 0output
-1 -1
贪心加细节
/*************************************************************************
> File Name: cf.cpp
> Author: acvcla
> QQ:
> Mail: acvcla@gmail.com
> Created Time: 2014年11月17日 星期一 23时34分13秒
************************************************************************/
#include
#include
#include
#include
#include
#include
D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!
Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections a, b, c and d, such that there are two paths from a to c ― one through b and the other one through d, he calls the group a "damn rhombus". Note that pairs (a, b), (b, c), (a, d), (d, c) should be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:
Other roads between any of the intersections do