#P10577. [蓝桥杯 2024 国 A] 兔子集结
[蓝桥杯 2024 国 A] 兔子集结
Problem Description
In a quiet corner of the forest, there is a village where rabbits live.
On a moonlit night, these rabbits line up in a row and prepare to start a rally jumping activity. Each rabbit occupies a position in the village. For rabbit , its position is . We call a smaller position “to the left” and a larger position “to the right”.
According to the village tradition, each rabbit will choose the rabbit closest to itself as its partner and jump in the direction of that partner. If the nearest rabbit on the left and on the right are at the same distance, it will choose the rabbit on the left as its partner.
Each jump of a rabbit can only move one unit to the left or to the right. That is, if a rabbit is currently at position , then after its next jump it will be at or .
When the distance between two rabbits moving toward each other becomes , the rabbit on the left will stay where it is, while the rabbit on the right will jump onto the left rabbit’s position, completing the rally.
The rabbits will keep jumping until they complete the rally with the partner they initially chose, and then stop.
After all rabbits have completed the rally, at which position will each rabbit end up?
Input Format
The first line contains an integer , representing the number of rabbits.
The second line contains integers , separated by single spaces, representing the initial positions of the rabbits.
Output Format
Output one line containing integers, representing the position of each rabbit after it completes the rally.
5
2 5 7 9 1
1 6 6 6 1
Hint
Sample Explanation
Rabbit chooses rabbit as its partner, and rabbit chooses rabbit as its partner. Since the distance between them is , rabbit stays where it is, while rabbit jumps to position and completes the rally with rabbit .
Rabbit chooses rabbit as its partner, and rabbit also chooses rabbit as its partner. For rabbit , rabbits and are at the same distance from it, so it chooses the left rabbit as its partner. Rabbit jumps one position to the right, rabbit jumps one position to the left, and rabbit jumps one position to the left. At this moment, rabbits and are both at position , completing the rally (stopping jumping). Rabbit will continue jumping left until it jumps to position and completes the rally with rabbit .
Constraints
For of the testdata, , , and are all distinct.
For all testdata, , , and are all distinct.
Translated by ChatGPT 5