Logo
(追記) (追記ここまで)

11761번 - Shuffling Along 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB107716572.222%

문제

Most of you have played card games (and if you haven’t, why not???) in which the deck of cards is randomized by shuffling it one or more times.

A perfect shuffle is a type of shuffle where the initial deck is divided exactly in half, and the two halves are perfectly interleaved. For example, a deck consisting of eight cards ABCDEFGH (where A is the top card of the deck) would be divided into two halves ABCD and EFGH and then interleaved to get AEBFCGDH. Note that in this shuffle the original top card (A) stays on top — this type of perfect shuffle is called an out-shuffle. An equally valid perfect shuffle would start with the first card from the second half and result in EAFBGCHD — this is known as an in-shuffle.

While normal shuffling does a good job at randomizing a deck, perfect shuffles result in only a small number of possible orderings. For example, if we perform multiple out-shuffles on the deck above, we obtain the following:

ABCDEFGH → AEBFCGDH → ACEGBDFH → ABCDEFGH → · · ·

So after 3 out-shuffles, the deck is returned to its original state. A similar thing happens if we perform multiple in-shuffles on an 8-card deck, though in this case it would take 6 shuffles before we get back to where we started. With a standard 52 card deck, only 8 out-shuffles are needed before the deck is returned to its original order (talented magicians can make use of this result in many of their tricks). These shuffles can also be used on decks with an odd number of cards, but we have to be a little careful: for out-shuffles, the first half of the deck must have 1 more card than the second half; for in-shuffles, it’s the exact opposite. For example, an out-shuffle on the deck ABCDE results in ADBEC, while an in-shuffle results in CADBE.

For this problem you will be given the size of a deck and must determine how many in- or outshuffles it takes to return the deck to its pre-shuffled order.

입력

The input consists of one line containing a positive integer n ≤ 1000 (the size of the deck) followed by either the word in or out, indicating whether you should perform in-shuffles or out-shuffles.

출력

For each test case, output the case number followed by the number of in- or out-shuffles required to return the deck to its original order.

제한

예제 입력 1

8 out

예제 출력 1

3

예제 입력 2

8 in

예제 출력 2

6

예제 입력 3

52 out

예제 출력 3

8

예제 입력 4

53 out

예제 출력 4

52

힌트

출처

ICPC > Regionals > North America > East Central North America Regional > 2015 East Central Regional Contest 연습 세션 PC번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /