Topic linksproblem 2111 Min numberaccept:499 submit:949
Time limit:1000 mSec Memory limit:32768 KB problem Description
Now is given one non-negative integer n in 10-base notation, it'll only contain digits (' 0 '-' 9 '). You is allowed to choose 2 integers i and j, such that:i!=j, 1≤i<j≤|n|, here |n| means the length of n ' s 10-base notation. Then we can swap n[i] and n[j].
For example, n=9012, we choose I=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original N.
Now you are allowed to operate at the most M times, so what's the smallest number can get after the the operation (s)?
Problem, leading zero is not allowed!
Input
The first line of the input contains an integer T (t≤100), indicating the number of the test cases.
Then T-cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤m≤100)
Outputfor Each test case, the output of the minimum number we can get after no more than M operations. Sample Input39012 09012 19012 2 Sample Output901210921029
Each operation can be changed to two digits on the number
Up to M operations
What is the minimum number that can be obtained after the operation?
Greed, the first bit can not be zero, and then find the smallest number constantly placed in the front of the number of digits.
9,012 the first position can not be 0 so the rest of the smallest 1 in the first 1092; the second is already the smallest so the third place 9 is replaced by the remaining smallest 2 to 1029;
Min number greedy, put the smallest numbers in the top