CF1808C.Unlucky Numbers
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In this problem, unlike problem A, you need to look for unluckiest number, not the luckiest one.
Note that the constraints of this problem differ from such in problem A.
Olympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.
Each starship has a number —some positive integer x. Let's define the luckiness of a number x as the difference between the largest and smallest digits of that number. For example, 142857 has 8 as its largest digit and 1 as its smallest digit, so its luckiness is 8−1=7. And the number 111 has all digits equal to 1, so its luckiness is zero.
Hateehc is a famous Martian blogger who often flies to different corners of the solar system. To release interesting videos even faster, he decided to buy himself a starship. When he came to the store, he saw starships with numbers from l to r inclusively. While in the store, Hateehc wanted to find a starship with the unluckiest number.
Since there are a lot of starships in the store, and Hateehc can't program, you have to help the blogger and write a program that answers his question.

本题与 A 题不同,你需要寻找的是“最不幸运”的数字,而非“最幸运”的数字。
注意:本题的约束条件与 A 题不同。
奥林匹斯城近期启动了个人星际飞船的量产。如今,火星上的每个人均可购买一艘,并以低廉成本飞往其他行星。
每艘星际飞船都有一个编号——某个正整数 x。我们定义数字 x 的“幸运度”为该数各位数字中最大值与最小值之差。例如,142857 的最大数字为 8,最小数字为 1,因此其幸运度为 8−1=7;而数字 111 的所有数字均为 1,故其幸运度为 0。
Hateehc 是一位著名的火星博主,经常飞往太阳系各个角落。为了更快地发布有趣的视频,他决定为自己购置一艘星际飞船。当他来到商店时,发现店内陈列的飞船编号为从 l 到 r(含端点)的所有整数。在店内,Hateehc 希望找到一艘编号“最不幸运”的飞船。
由于店内飞船数量众多,而 Hateehc 不会编程,你必须帮助这位博主,编写一个程序来回答他的问题。

输入格式
The first line contains an integer t (1≤t≤600) —the number of test cases.
Each of the following t lines contains a description of the test case. The description consists of two integers l, r (1≤l≤r≤1018) — the largest and smallest numbers of the starships in the store.
第一行包含一个整数 t(1≤t≤600)——测试用例的数量。
接下来的 t 行,每行描述一个测试用例。每行包含两个整数 l、r(1≤l≤r≤1018)——商店中星际飞船编号的最小值和最大值。
输出格式
Print t lines, one line for each test case, containing the unluckiest starship number in the store.
If there are several ways to choose the unluckiest number, output any of them.
输出 t 行,每行对应一个测试用例,包含商店中最不幸运的星舰编号。
如果存在多种选择最不幸运编号的方式,则输出其中任意一个即可。
输入输出样例
输入#1
5 59 63 42 49 48 53 90 90 1 100
输出#1
63 44 53 90 1
说明/提示
Let's look at two test examples:
- the luckiness of the number 59 is 9−5=4;
- the luckiness of 60 equals 6−0=6;
- the luckiness of 61 equals 6−1=5;
- the luckiness of 62 equals 6−2=4;
- the luckiness of 63 is 6−3=3.
So the unluckiest number is 63.
In the fifth test case, the unluckiest numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, so you are allowed to choose any of them.
我们来看两个测试样例:
- 数字 59 的“幸运值”为 9−5=4;
- 60 的幸运值为 6−0=6;
- 61 的幸运值为 6−1=5;
- 62 的幸运值为 6−2=4;
- 63 的幸运值为 6−3=3。
因此,最“不幸”的数字是 63。
在第五个测试用例中,最不幸的数字有 1、2、3、4、5、6、7、8、9、11、22、33、44、55、66、77、88、99,因此你可以任选其中任意一个。
输入解题思路,AI测评打分。不知道怎么写?