JUNL - BHAAD MEI JAAO
You are on vacation on a drunken island, but you couldn't resist the temptation of solving a good old problem. It all started when a group of kids played a game they call "The Falling Coconuts". In this game, a number of coconuts fall to the ground, one by one, on a single axis, at the locations given in drops. If a coconut X lands on the ground, it remains where it is. If it lands on top of another coconut Y, one of the following things happens:
- If coconut Y is surrounded on both sides by coconuts (denoted by 'O'), coconut X remains where it is.
- If there is no coconut directly to the right of coconut Y, coconut X slides down to the position directly to the right of coconut Y.
OY -> OYX
Y -> YX
- If there is a coconut directly to the right of coconut Y, but no coconut directly to the left of coconut Y, coconut X slides down to the position directly to the left of coconut Y.
YO -> XYO
Each time coconut X slides down to a different position, it will continue to slide (following the behavior outlined above) until it's in a place where it will not slide any further.
The task is to display the final coconut configuration.
First line is t = number of test cases.
Each test case consists of 2 lines , first line conataining the number of coconuts and second line contains n integers denoting the position of each cocnut on the x-axis.
As described in the problem statement.
8 9 10 11 12 8 12 10
6 8 10 7 9 8 8 8 8 8 Output:
Explanation of test case 1:
The configuration after each fallen coconut is given below: X X -> OX -> OOX -> 000X -> 0000X -> X00000 -> 000000X -> 0000000 In this diagram, 'X' denotes the last fallen coconut.
Can someone please explain the output sequence of second testcase?
Yes, on top of what Jared had written, print an empty line after each test case. I don't know if exact judge is used though, so maybe white space do not matter.
Very well put jared.. :)
Initial position: 0 ≤ Pi ≤ 18
do we need to print '-' too ?
The output description is strange and is compounded by the blank lines. Remove the blank lines between the first two outputs, and remove the lines between the final 3 outputs, and it will make more sense.
You can assume n<100
Snehasish Roy ;):
Output description is not clear :D