CF1649A 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$ 是水。

输出格式

对于每组测试数据输出一行一个整数表示问题的答案。

说明/提示

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.