CF1900A.Cover in Water

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Filip has a row of cells, some of which are blocked, and some are empty. He wants all empty cells to have water in them. He has two actions at his disposal:

  • 11 — place water in an empty cell.
  • 22 — remove water from a cell and place it in any other empty cell.

If at some moment cell ii (2≤i≤n−12 \le i \le n-1) is empty and both cells i−1i-1 and i+1i+1 contains water, then it becomes filled with water.

Find the minimum number of times he needs to perform action 11 in order to fill all empty cells with water.

Note that you don't need to minimize the use of action 22. Note that blocked cells neither contain water nor can Filip place water in them.

菲利普有一排单元格,其中一些被阻塞,另一些为空。他希望所有空单元格中都充满水。他可以执行以下两种操作:

  • 11 — 在一个空单元格中放置水;
  • 22 — 将某个单元格中的水移除,并将其放置到任意其他空单元格中。

若在某一时刻,单元格 ii(其中 2≤i≤n−12 \le i \le n-1)为空,且其左右相邻单元格 i−1i-1 和 i+1i+1 均含有水,则该单元格 ii 会自动被水填满。

求为使所有空单元格均被水填满,所需执行操作 11 的最小次数。

注意:你无需最小化操作 22 的使用次数。另外,被阻塞的单元格既不能存水,菲利普也不能向其中放置水。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of cells.

The next line contains a string ss of length nn. The ii-th character of ss is '.' if the cell ii is empty and '#' if cell ii is blocked.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示单元格的数量。

下一行包含一个长度为 nn 的字符串 ss。字符串 ss 的第 ii 个字符为 '.' 表示第 ii 个单元格为空,为 '#' 表示第 ii 个单元格被阻塞。

输出格式

For each test case, output a single number — the minimal amount of actions 11 needed to fill all empty cells with water.

对于每个测试用例,输出一个整数——即填满所有空单元格所需的最少操作次数 11。

输入输出样例

  • 输入#1

    5
    3
    ...
    7
    ##....#
    7
    ..#.#..
    4
    ####
    10
    #...#..#.#

    输出#1

    2
    2
    5
    0
    2

说明/提示

Test Case 1

In the first test case, Filip can put water in cells 11 and 33. As cell 22 is between 22 cells with water, it gets filled with water too.

Test Case 2

In the second case, he can put water sources in cells 33 and 55. That results in cell 44 getting filled with water. Then he will remove water from cell 55 and place it into cell 66. As cell 55's neighbors, cell 44 and cell 66, have water in them, cell 55 also gets filled with water. You can see the illustration of this case below.

Operations in the second test case. White cells are empty, grey ones are blocked, and blue ones are water.

Test Case 3

In the third case, he can put water in all the empty cells. That requires 55 actions of type 11.

Test Case 4

In the fourth case, there are no empty cells. Therefore, he does not have to put any water in them.

Test Case 5

In the fifth test case, there exists a sequence of actions that requires only 22 type 11 actions.

测试用例 1

在第一个测试用例中,Filip 可以在第 11 和第 33 个格子中注水。由于第 22 个格子位于两个有水的格子之间,它也会被水填满。

测试用例 2

在第二个测试用例中,他可以在第 33 和第 55 个格子中放置水源。这将导致第 44 个格子被水填满。随后,他将第 55 个格子中的水移除,并将其注入第 66 个格子。由于第 55 个格子的相邻格子(即第 44 和第 66 个格子)均有水,因此第 55 个格子也会被水填满。该情况的示意图如下所示。

第二个测试用例中的操作。白色格子为空,灰色格子为障碍物,蓝色格子为水。

测试用例 3

在第三个测试用例中,他可以向所有空格子中注水。这需要执行 55 次类型 11 的操作。

测试用例 4

在第四个测试用例中,不存在空格子。因此,他无需向任何格子中注水。

测试用例 5

在第五个测试用例中,存在一种仅需 22 次类型 11 操作的操作序列。

输入解题思路,AI测评打分。不知道怎么写?

首页