Nine Chapters count judges Net-original website
http://www.jiuzhang.com/problem/38/
Topics
There is a pair of poker with 2n cards, with,.. 2*n represents each card, a shuffle will divide the cards into two piles, 1,2..N and n+1...2n. Then cross the wash Together: n+1, 1, n+2, 2, ... n, 2n. Ask how many times you can wash back the initial state of poker by shuffling this technique:,... 2n.
Answer
Take 1 2 3 4 5 6 For example, after washing for 4 1 5 2 6 3. Compare two rows of arrays to see:
1 2 3 4 5 6
4 1 5 2 6 3
The number 1 below is 4, representing each shuffle after 1 This position number will be 4 this position of the number of substitution, and then see the number is 2 below, for each shuffle after 4 this position number will be 2 instead, see 2,2 below is the number of this position will be 1 instead. At this time, 1 4 2 form a ring, representing the number of these three positions after each shuffle, the cycle alternating, and after washing 3 times, each returned to the original position. The same method can be found 3 5 6 is a cycle, the length of the link is 3. It can be known that after the LCM (3,3) = 3 Shuffle, all the numbers are back to their original position, where the LCM is the meaning of least common multiple. So the algorithm is, according to the results of a shuffle, find all the cycle section, the answer for all the length of the Loop section least common multiple.
Interviewer Angle
The point of this problem is to find the law. However, if there is a certain displacement group of the theoretical basis of the students, it can be relatively easy to solve the problem. Interested students can view the knowledge points of permutation groups in the related books of discrete mathematics.
Nine chapters algorithm surface question 38 Shuffle skill