Nine chapters algorithm surface question 38 Shuffle skill

Source: Internet
Author: User
Tags shuffle

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.