Public Judge

pjudge

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#21669. 【NOIP Round #1】一维围棋

統計

题目描述

小 $w$ 和小 $b$ 在下围棋,与传统围棋不同,他们是在一个由 $n$ 个格子排成一行构成的棋盘上博弈,每个格子至多放一个棋子。

我们设从左到右第 $i$ 个格子上的棋子为 $S_i$,$S_i\in\{W,B,\cdot\}$,分别表示这是一个白色的棋子,或黑色的棋子,或没有棋子。

假如存在区间 $[l,r]$,使得 $r-l+1\ge 3$,并且这个区间内的格子全部都放了棋子。此时如果 $l+1,\dots,r-1$ 这些格子上的棋子同色,但 $l,r$ 这两个格子上的棋子与它们异色,则称 $l+1,\dots,r-1$ 这些格子上的棋子被占领了。比如,如果有 WWBBW.WB,则第三、四个格子上的棋子被占领了。

现在给定 $S_i$,保证现在没有任何棋子被占领。并且下一步是小 $w$ 下,也就是说,小 $w$ 要选一个位置放一个白棋子,要求小 $w$ 放棋子之后没有白棋子被占领(保证一定存在方案可以做到这一点)。

小 $w$ 希望他放棋子后占领黑棋子数量最多,但是他棋艺不精,所以找到了你来帮他算出这个数字。

输入格式

一行一个正整数 $n$ 以及一个长度为 $n$ 的只包含 B,W,.​ 的字符串,表示 $\{S_i\}$。

输出格式

一行一个整数表示占领黑棋子的最大数量。

样例

输入1

5 .WB..

输出1

1

我们可以把棋子放在第三个格子,这样第二个格子的黑棋子就会被占领。

输入2

5 WB.B.

输出2

0

假如把棋子放在第三个格子,那么这个棋子就会被占领,不符合题目要求。所以我们只能把棋子放在第五个格子并不占领任何棋子。

样例输入/输出 3

见下发文件中的 ex_capture3.in/ex_capture3.ans

样例输入/输出 4

见下发文件中的 ex_capture4.in/ex_capture4.ans

数据范围

对于 $30\%$ 的数据,保证恰好存在一个 $i$ 使得 $S_i=B$。

对于另 $5\%$ 的数据,保证 $\forall i,S_i\ne W$。

对于 $100\%$ 的数据,保证 $1\le n\le 100$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.