#P7912. [CSP-J 2021] 小熊的果篮
[CSP-J 2021] 小熊的果篮
Problem Description
In Little Bear’s fruit shop, there is a row of fruits. Each fruit is either an apple or an orange, numbered from left to right with positive integers . A consecutive segment of the same kind of fruit is called a “block”. Little Bear wants to pick the fruits in this row into several baskets. The method is as follows: each time, the leftmost fruit in every “block” is picked out simultaneously to form one basket. Repeat this operation until all fruits are picked.
Note that after picking one basket, the “blocks” may change. For example, if the only orange between two apple “blocks” is picked out, then the two apple “blocks” will merge into one “block”. Please help Little Bear determine which fruits are contained in each basket.
Input Format
The first line contains a positive integer , the number of fruits.
The second line contains integers separated by spaces. The -th number indicates the type of the fruit numbered : represents an apple, and represents an orange.
Output Format
Output several lines.
The -th line describes the basket formed by the -th picking operation. Output the indices of all fruits in that basket in increasing order, separated by one space between every two indices.
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
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
见附件中的 fruit/fruit3.in。
见附件中的 fruit/fruit3.ans。
Hint
Sample Explanation #1
This is the sample description for the first set of testdata.
Initially, the fruits are , with a total of blocks.
During the first picking operation, fruits numbered are picked out.
After that, the remaining fruits are , with a total of blocks.
During the second picking operation, fruits numbered are picked out.
After that, the remaining fruits are , with only block.
During the third picking operation, the fruit numbered is picked out.
Finally, the remaining fruits are , with only block.
During the fourth picking operation, the fruit numbered is picked out.
Constraints
For of the data, .
For of the data, .
For of the data, .
For of the data, .
Hint
Because the data size is large, C/C++ users are advised to use scanf and printf for input and output.
Translated by ChatGPT 5