#K75227. Reversal Card Shuffle
Reversal Card Shuffle
Reversal Card Shuffle
You are given a deck of cards represented by a sequence of integers. Your task is to perform a reversal shuffle on the deck. In a reversal shuffle, the deck is divided into k sub-decks. The size of each sub-deck is determined using the formulas:
\(\text{Sub-deck size} = \left\lfloor \frac{n}{k} \right\rfloor\)
and the first \(n \bmod k\) sub-decks receive one extra card each. In each sub-deck, the order of cards is reversed. Finally, all the reversed sub-decks are concatenated in the original order to form the final deck.
The input terminates with a line containing "0 0".
inputFormat
The input consists of multiple test cases. For each test case:
- The first line contains two integers, k and n, where k is the number of sub-decks and n is the total number of cards.
- The second line contains n integers representing the deck.
The input terminates with a line containing "0 0" which should not be processed.
outputFormat
For each test case (except for the termination indicator), output a single line containing the final shuffled deck. The cards should be printed in order and separated by a single space.
## sample2 7
1 2 3 4 5 6 7
3 6
10 20 30 40 50 60
0 0
4 3 2 1 7 6 5
20 10 40 30 60 50
</p>