#P10901. [蓝桥杯 2024 省 C] 封闭图形个数
[蓝桥杯 2024 省 C] 封闭图形个数
Problem Description
In the Lanqiao Kingdom, the size of a number depends not only on its numerical value, but also on the number of “closed shapes” it forms.
A closed shape refers to a completely enclosed space inside a digit. For example, digits , , , , do not form any closed shapes, while digits , , , each form closed shape, and digit forms closed shapes. Note that the number of closed shapes can be added up. For example, for the number , since forms closed shape and forms closed shapes, the total number of closed shapes formed by is .
When comparing two numbers, if their numbers of closed shapes are different, then the number with more closed shapes is larger. For example, the numbers and have and closed shapes respectively, so is smaller than . If two numbers have the same number of closed shapes, then the number with the larger numerical value is larger. For example, the numbers and both have closed shape, but , so is smaller than . If two numbers have the same number of closed shapes and the same numerical value, then they are considered equal.
Xiao Lan is very interested in the rules for comparing numbers in the Lanqiao Kingdom. Now, you are given numbers . Please sort these numbers in non-decreasing order according to the Lanqiao Kingdom’s rules, and output the sorted result.
Input Format
The first line contains an integer , indicating the number of given numbers.
The second line contains integers , separated by a single space, representing the numbers to be sorted.
Output Format
Output one line containing integers, separated by a single space, representing the result after sorting in non-decreasing order according to the Lanqiao Kingdom’s rules.
3
18 29 6
6 29 18
Hint
[Sample Explanation]
For the given sequence , the number has closed shapes, has closed shape, and has closed shape. Sorting by the number of closed shapes from small to large yields .
Since and have the same number of closed shapes, we further sort them by numerical value, and finally get .
[Constraints and Conventions]
For of the testdata, , .
For all testdata, , .
Translated by ChatGPT 5