Sort the given decimals by the round in which repeated middle-third deletion removes them, listing numbers that survive every round last in increasing order.
Medium7MathSimulationSortingNo attempts yetTime limit5sMemory limit512 MBThere is a pool of numbers, and all of them are decimal fractions from the interval (0,1). In the first round of the game the middle third of the interval disappears, and every number that falls in it is removed from the pool. In each later round the middle third of every remaining interval disappears. The first round removes the interval [1/3,2/3], the second round removes [1/9,2/9] and [7/9,8/9], and it goes on in the same way. The endpoints of a removed interval are removed with it.
List the numbers of the pool in the order they are removed. Numbers that are never removed come last. Among numbers that share a position, write the smaller one first.
The first line contains the number of test cases T. Each test case starts with a line holding the count N, followed by N lines with one number each. Every number starts with 0. and continues with one or more digits. Every number is larger than zero and has no trailing zeros.
For each test case print the line Case #x:, where x is the number of the test case, starting from 1. After that line print the numbers in the order they are removed, one per line, written exactly as they appear in the input. A number given several times is printed that many times.
In the first case of the first example, 0.5 falls in the interval [1/3,2/3], so it is removed in the first round. After the first round the intervals (0,1/3) and (2/3,1) remain. The number 0.12 falls in [1/9,2/9], so it is removed in the second round. In the second case, 0.1 and 0.9 are never removed, so they come last, the smaller one first.