#CSPJ2021D. 小熊的果篮 (Bear's Fruit Basket)
小熊的果篮 (Bear's Fruit Basket)
Description
Bear's fruit shop has a row of fruits. Each fruit is either an apple or an orange, numbered from left to right using positive integers . The same kind of fruits appearing together is called a "block". The bear has to pick the row of fruits into several fruit baskets: each time, pick the leftmost fruit in each block simultaneously to form a fruit basket. Repeat this operation until there's no fruit left. Note that the "blocks" may change after each picking of a fruit basket. For example, when the only orange between two apple "blocks" is picked, the two apple "blocks" become one "block". Please help the bear to figure out the fruits contained in each fruit basket.
Input Format
Read input from the file fruit.in
.
The first line contains a positive integer denoting the number of fruits.
The second line contains space-separated integers where the -th integer denotes the type of fruit ( for apples and for oranges).
Output Format
Write output to the file fruit.out
.
Print several lines.
The -th line should correspond to the fruit basket consisting of the fruits picked in the -th picking. Print the numbers of all fruits in the basket sorted in increasing order and separated by spaces.
12
1 1 0 0 1 1 1 0 1 1 0 0
1 3 5 8 9 11
2 4 6 12
7
10
Initially, the row of fruits is . There are a total of blocks.
In the first picking of fruits to form a fruit basket, the fruits numbered are picked.
Now the remaining fruits are . There are a total of blocks.
In the second picking of fruits to form a fruit basket, the fruits numbered are picked.
The remaining fruits are . There is only block.
In the third picking of fruits to form a fruit basket, the fruit numbered is picked.
The last remaining fruit is , and there is only block.
In the fourth picking of fruits to form a fruit basket, the fruit numbered is picked.
20
1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0
1 5 8 11 13 14 15 17
2 6 9 12 16 18
3 7 10 19
4 20
Sample 3
See fruit3.in and fruit3.ans.
Constraints
For of the data, .
For of the data, .
For of the data, .
For of the data, .
Due to the large size of the data, it is recommended that C/C++ users use scanf
and printf
for input and output.