22842_CowShuffle

2022-5-16 18:23| 发布者: Hocassian| 查看: 31| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-8950711257099-Problem List-采集的数据-后羿采集器.html

Pro.ID

22842

Title

Cow Shuffle

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22842

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Each time cows shuffle a deck of 2N (1 ≤ N ≤ 9,000) cards marked 1..2N they do it as follows:

    * Cut the deck exactly in half to form two piles (A and B) of N cards each. A is the top N cards and B is the bottom N cards.

    * Combine the cards back together into a single pile by taking one card from pile A and placing it face down on a new pile and then one card from pile B and placing it face down on top of the first card, then one from A and one from B and so on until all the cards are perfectly shuffled back into a single pile.

    They repeat this cow shuffle again and again until the cards are back in their original order.

    Given N, how many cow shuffles does it take to return the cards to their original order?

    EXAMPLE:

    Let N be 3; therefore, the the cards are {1, 2, 3, 4, 5, 6} and the shuffles go like this:

    orig   shuf1  shuf2   shuf3  shuf4
     1      6      1      6      1
     2      3      5      4      2
     3   -> 5   -> 4   -> 2   -> 3
     4      2      3      5      4
     5      4      2      3      5
     6      1      6      1      6

    So, four cow shuffles suffice to put the deck of three cards back in order.

    输入

    A single line with the integer N

    输出

    Description

    Each time cows shuffle a deck of 2N (1 ≤ N ≤ 9,000) cards marked 1..2N they do it as follows:

    * Cut the deck exactly in half to form two piles (A and B) of N cards each. A is the top N cards and B is the bottom N cards.

    * Combine the cards back together into a single pile by taking one card from pile A and placing it face down on a new pile and then one card from pile B and placing it face down on top of the first card, then one from A and one from B and so on until all the cards are perfectly shuffled back into a single pile.

    They repeat this cow shuffle again and again until the cards are back in their original order.

    Given N, how many cow shuffles does it take to return the cards to their original order?

    EXAMPLE:

    Let N be 3; therefore, the the cards are {1, 2, 3, 4, 5, 6} and the shuffles go like this:

    orig   shuf1  shuf2   shuf3  shuf4
     1      6      1      6      1
     2      3      5      4      2
     3   -> 5   -> 4   -> 2   -> 3
     4      2      3      5      4
     5      4      2      3      5
     6      1      6      1      6

    So, four cow shuffles suffice to put the deck of three cards back in order.

    Input

    A single line with the integer N

    Output

    A single line with the integer number of shuffles required to return 2N cards to their original order.

    Sample Input

    3

    Sample Output

    4

    Source

    样例输入

    3

    样例输出

    4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部