当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6917:Shorten the array

题目描述
Alice has an array $a$. The array has $N$ positive numbers. She thinks the array is too long, so she wants to shorten the array. She decides to shorten the array via the following operation: every time she will choose an index $i$ $(1 \le i<n)$ which $a_i > 0$ and $a_{i+1} > 0$. She will delete $a_i$ and $a_{i+1}$ and use $(a_i\operatorname{mod} a_{i+1})$ or $(a_{i+1}\operatorname{mod} a_{i})$ to replace them.

For example, for array $[3, 2, 4, 5]$, if Alice choose $i=2$, she can change the array to $[3, 2, 5]$ or $[3, 0, 5]$. Alice wants you to tell her the shortest possible length of the array after several options.
输入解释
The first line contains a single integer $T$ $(1 \le T \le 10)$, indicating the number of test cases.

For each test cases:

The first line contains one integer $N$ $(2 \le N \le 10^6)$, indicating the size of the array.

The next line contains $N$ integers $a_i$ $(a_i \le 10^{9})$, representing the array.
输出解释
Output $T$ lines.

The $i$-th line contains a single integer, representing the answer of $i$-th test case.
输入样例
2
4
1 1 1 1
4
2 3 4 5
输出样例
2
1

提示
For the first sample, Alice first choose $i=1$ to change the array to $[0, 1, 1]$, then choose $i=2$ to change the array to $[0, 0]$, which is the best result she can reach.
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6917

最后修改于 2021-06-22T18:18:53+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)