아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Untie

면접 대비

시간 제한10초메모리 제한1024 MB

요약
R, P, S로 이루어진 원형 문자열에서 이웃한 두 문자가 같지 않도록 바꿔야 하는 문자의 최소 개수를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디, 문자열, 완전 탐색
정답자
아직 제출이 없습니다

문제

A group of people are sitting in a circle, playing a special version of rock, paper, scissors. In this game, each person chooses rock, paper, or scissors in secret and then everyone reveals their choice to everyone else. Each person then compares their selection to their two neighbors, and can win, lose, or tie against each of them independently. The only way to tie is when both people make the same choice.

You want to make it so that no game is a tie. For each player, you can let them keep their choice, or you can ask them to change to any of the other two options (you choose to which one). What is the minimum number of people you need to request a change from to ensure that there are no ties between neighbors after those changes are made?

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} lines follow. Each line represents a test case and contains a string C\mathbf{C}. The ii-th character of C\mathbf{C} represents the original choice of the ii-th person in clockwise order using an uppercase R to mean rock, an uppercase P to mean paper, and an uppercase S to mean scissors.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of changes that are required such that no two neighbors end up with the same choice.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • Each character of C\mathbf{C} is either an uppercase R, an uppercase P, or an uppercase S.

힌트

In Sample Case #1, there is a pair of neighbors that both chose paper (the first and last character of the input) and another pair that both chose scissors. Therefore, we need at least two changes. One way of doing it with two changes is to change the leftmost paper to scissors and the rightmost scissors to rock, to obtain SRSRP.

In Sample Case #2, all 77 participants chose rock. If we change at most 33 selections, there will be at least 44 remaining rocks, and at least two of them will be neighbors. Therefore, the minimum number of changes is at least 44. One way to achieve exactly 44 is to get PRSRPRS.

In Sample Case #3, no pair of neighbors tied, so no changes are needed.

예제1

  1. 예제 1

    입력
    3
    PRSSP
    RRRRRRR
    RSPRPSPRS
    
    예상 출력
    Case #1: 2
    Case #2: 4
    Case #3: 0