每日头条!CF 1649A - Game

2023-06-22 09:59:06 来源:哔哩哔哩

You are playing a very popular computer game. The next level consists of n consecutive locations, numbered from 1 to n


【资料图】

, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if you become inside a location with water, you will die, so you can only move between locations with land.

You can jump between adjacent locations for free, as well as no more than once jump from any location with land i to any location with land i+x

, spending x coins (x≥0).

Your task is to spend the minimum possible number of coins to move from the first location to the last one.

Note that this is always possible since both the first and last locations are the land locations.

Input

There are several test cases in the input data. The first line contains a single integer t (1≤t≤100) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains one integer n (2≤n≤100) — the number of locations.

The second line of the test case contains a sequence of integers a1,a2,…,an (0≤ai≤1), where ai=1 means that the i

-th location is the location with land, and ai=0 means that the i

-th location is the location with water. It is guaranteed that a1=1 and an=1.

Output

For each test case print a single integer — the answer to the problem.

Example

input

3

2

1 1

5

1 0 1 0 1

4

1 0 1 1

output

0

4

2

Note

In the first test case, it is enough to make one free jump from the first location to the second one, which is also the last one, so the answer is 0.

In the second test case, the only way to move from the first location to the last one is to jump between them, which will cost 4 coins.

In the third test case, you can jump from the first location to the third for 2 coins, and then jump to the fourth location for free, so the answer is 2. It can be shown that this is the optimal way.

中文翻译:

您正在玩一款非常流行的电脑游戏。 下一级由n个连续的位置组成,编号从1到n

,每个区域都包含土地或水。 众所周知,第一个和最后一个位置包含土地,要完成关卡,您必须从第一个位置移动到最后一个位置。 另外,如果你进入有水的地方,你就会死,所以你只能在有陆地的地方之间移动。

您可以免费在相邻位置之间跳跃,并且从任何有土地 i 的位置跳跃到任何有土地 i+x 的位置不超过一次,花费 x 个硬币(x≥0)。

您的任务是花费尽可能少的硬币从第一个位置移动到最后一个位置。

请注意,这始终是可能的,因为第一个位置和最后一个位置都是陆地位置。

输入

输入数据中有几个测试用例。 第一行包含一个整数 t (1≤t≤100) — 测试用例的数量。 接下来是测试用例描述。

每个测试用例的第一行包含一个整数 n

(2≤n≤100) — 位置数。

测试用例的第二行包含整数序列a1,a2,…,an (0≤ai≤1),其中ai=1表示第i个位置是有土地的位置,ai=0表示 第 i 个位置是有水的位置。 保证a1=1且an=1。

输出

对于每个测试用例,打印一个整数——问题的答案。

其实就是找到左右0的位置,相减即可,没有0则返回0.有0则返回索引的差值+1;

下面是代码:

关键词:

上一篇: 宋山木强奸事件
下一篇: 最后一页