#P9846. Touhou Red Red Blue
Touhou Red Red Blue
Touhou Red Red Blue
Problem Description
You are playing a game called Touhou Red Red Blue. In this game, you will receive mini UFOs (Undefined Fantastic Object) one by one, and you can decide to store or discard each UFO at the time you receive it. Each UFO has one of these three colors: R, G, and B. You have two bags numbered and , which are initially empty. When you decided to store a UFO (marked as ) and at least one bag is empty:
- If bag is empty, store in bag .
- If bag is not empty and bag is empty, store in bag . When you decided to store a UFO (marked as ) and no bag is empty, we consider the three UFOs we stored(the current one, the one in the bag , and the one in the bag ) :
- If all three UFOs have the same color, these three UFOs will disappear and you get point (this is the only way you can get points). After that, you will get an additional UFO (not in the given sequence) in your bag , which color can be decided by yourself.
- If all three UFOs have different colors with each other, these three UFOs will disappear. After that, you will get two additional UFOs (not in the given sequence) in your bag and bag , and you can decide their colors independently by yourself.
- Otherwise, you will discard the UFO in bag , move the UFO in bag to bag , and store in bag 2. What is the maximum points you can get after receiving all these UFOs?
Input
The first line contains one integer which represents the number of test cases. For each test case: One line contains one string consisting of uppercase letters 'R', 'G' and 'B', represents the color sequence of all the given UFOs.
Output
For each test case, print one line containing one integer which represents the most points you could get.
Sample Input
3
RRRRR
RBGG
RBRBR
Sample Output
2
1
1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(5)