-->
当前位置:首页 > 题库

PROGRAMMING:Zhuzi (Ningbo primary school, 2012)

Luz5年前 (2021-05-10)题库373
Weiwei's mother has a necklace made of a string of beads. The beads in this necklace can be up to three colors (red, blue and white, denoted by R, B and W respectively). One day, Weiwei wanted to take out some beads from her mother's necklace to play. Although her mother agreed, she put forward the following conditions:
(1) You can only choose one place to cut the necklace, and then take out the beads from the two ends of the broken necklace;
(2) If the color of the bead is the same as that of the first bead at each end, the bead can be removed continuously,
Until there is a bead with a different color from the first one at the end. If white beads are encountered, they can be seen as blue or white as needed
Red.
![ t1.png](~/67189312-0006-4252-a5a4-d3b5014767d4.png)
![ t2.png](~/9e0c9b1b-b5b5-42e5-b08d-57d5ead01207.png)
Weiwei has no special requirements for color, but she wants as many beads as possible.
For convenience, we number the beads in the necklace clockwise, as shown in figure-1 and figure-2
There are 11 beads in each necklace.
For figure-1, if the beads were cut between No. 1 and No. 2, a total of 2 beads could be obtained. And if
Cut between No. 6 and No. 7 beads, then the taste can get a total of 5 beads (3 red R on the left and 2 red R on the right)
Blue b), and 5 beads are also the maximum number of beads that Wei Wei can get from this necklace.
For the necklace in figure-2, if it is cut between No. 1 and No. 2 beads, a total of 4 beads can be taken (1
Take the No. 1 bead as blue, so 3 beads can be taken on the left and 1 bead can be taken on the right (b). And if you cut it between two and three,
Take 6 beads in total (take No. 1 bead as blue, so 4 blue B can be taken on the left and 2 red on the right)
Color R).
###Input format:
The input contains two lines. The first line is an integer n, which represents the total number of beads in the necklace. The second line is a string of characters of length N, which is composed of characters R, B and W. It indicates the arrangement of the beads of the necklace that start from a certain bead and unfold clockwise (of course, this bead is not necessarily the position where the taste actually needs to be cut).
###Output format:
The output contains only one value per line, which indicates the maximum number of beads that Wei Wei can get according to the rules of mother.
###Input sample 1:
```in
eleven
wbrrbbwbrbb
```
###Output sample 1:
```out
six
```
[explanation of input and output example 1] assume that the first character in the input string represents No. 1 bead
If No. 1 bead is regarded as blue, then cut between No. 2 and No. 3 beads, and the 6 beads obtained by Weiwei are numbered as
1、2、3、4、10、11; It can also be cut between No. 4 and No. 5 beads. If No. 7 bead is regarded as blue, the flavor can get beads
Their numbers are 3, 4, 5, 6, 7 and 8.
###Input sample 2:
```in
eleven
bbbbrbbbbrw
```
###Output sample 2:
```out
six
```
[data range]
For 60% of the data 3≤n≤100
For 100% data 3≤n≤350







answer:If there is no answer, please comment