309241: CF1649A. Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Game

题意翻译

### 题目描述 你正在玩一个十分流行的电脑游戏。下一关有连续的 $n$ 个位置,编号从 $1$ 到 $n$ 。每个位置上都是水或者陆地。你要从 $1$ 号位置移动到 $n$ 号位置。如果你走到水里,你会死。相邻位置之间的移动是免费的。你有且只有一次从位置 $i$ 跳到位置 $i+x$ 的机会,要花费 $x$ 金币。你想知道从 $1$ 号位置移动到 $n$ 号位置最少要花费多少金币。保证 $1$ 号位置和 $n$ 号位置是陆地。 ### 输入格式 第一行一个整数 $t (1 \le t \le 100)$ 表示测试数据组数。 每组数据的第一行包括一个整数 $n(1 \le n \le 100)$ ,表示位置数。 第二行有 $n$ 个整数 $a_i(0 \le a_i \le 1)$ ,其中 $a_i = 1$ 表示位置 $i$ 是陆地, $a_i = 0$ 表示位置 $i$ 是水。 ### 输出格式 对于每组测试数据输出一行一个整数表示问题的答案。

题目描述

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 \geq 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.

输入输出格式

输入格式


There are several test cases in the input data. The first line contains a single integer $ t $ ( $ 1 \leq t \leq 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 \leq n \leq 100 $ ) — the number of locations. The second line of the test case contains a sequence of integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \leq a_i \leq 1 $ ), where $ a_i = 1 $ means that the $ i $ -th location is the location with land, and $ a_i = 0 $ means that the $ i $ -th location is the location with water. It is guaranteed that $ a_1 = 1 $ and $ a_n = 1 $ .

输出格式


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

输入输出样例

输入样例 #1

3
2
1 1
5
1 0 1 0 1
4
1 0 1 1

输出样例 #1

0
4
2

说明

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.

Input

题意翻译

### 题目描述 你正在玩一个十分流行的电脑游戏。下一关有连续的 $n$ 个位置,编号从 $1$ 到 $n$ 。每个位置上都是水或者陆地。你要从 $1$ 号位置移动到 $n$ 号位置。如果你走到水里,你会死。相邻位置之间的移动是免费的。你有且只有一次从位置 $i$ 跳到位置 $i+x$ 的机会,要花费 $x$ 金币。你想知道从 $1$ 号位置移动到 $n$ 号位置最少要花费多少金币。保证 $1$ 号位置和 $n$ 号位置是陆地。 ### 输入格式 第一行一个整数 $t (1 \le t \le 100)$ 表示测试数据组数。 每组数据的第一行包括一个整数 $n(1 \le n \le 100)$ ,表示位置数。 第二行有 $n$ 个整数 $a_i(0 \le a_i \le 1)$ ,其中 $a_i = 1$ 表示位置 $i$ 是陆地, $a_i = 0$ 表示位置 $i$ 是水。 ### 输出格式 对于每组测试数据输出一行一个整数表示问题的答案。

加入题单

算法标签: