A15157 | Tokitsukaze and All Zero Sequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Tokitsukaze has a sequence $a$ of length $n$ . For each operation, she selects two numbers $a_i$ and $a_j$ ( $i \ne j$ ; $1 \leq i,j \leq n$ ).
- If $a_i = a_j$ , change one of them to $0$ .
- Otherwise change both of them to $\min(a_i, a_j)$ .
Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $0$ . It can be proved that the answer always exists.
- If $a_i = a_j$ , change one of them to $0$ .
- Otherwise change both of them to $\min(a_i, a_j)$ .
Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $0$ . It can be proved that the answer always exists.
输入格式
The first line contains a single positive integer $t$ ( $1 \leq t \leq 1000$ ) — the number of test cases.
For each test case, the first line contains a single integer $n$ ( $2 \leq n \leq 100$ ) — the length of the sequence $a$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \leq a_i \leq 100$ ) — the sequence $a$ .
For each test case, the first line contains a single integer $n$ ( $2 \leq n \leq 100$ ) — the length of the sequence $a$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \leq a_i \leq 100$ ) — the sequence $a$ .
输出格式
For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $0$ .
输入输出样例
输入 #1
3 3 1 2 3 3 1 2 2 3 1 2 0
输出 #1
4 3 2
In the first test case, one of the possible ways to change all numbers in the sequence to $0$ :
In the $1$ -st operation, $a_1 < a_2$ , after the operation, $a_2 = a_1 = 1$ . Now the sequence $a$ is $[1,1,3]$ .
In the $2$ -nd operation, $a_1 = a_2 = 1$ , after the operation, $a_1 = 0$ . Now the sequence $a$ is $[0,1,3]$ .
In the $3$ -rd operation, $a_1 < a_2$ , after the operation, $a_2 = 0$ . Now the sequence $a$ is $[0,0,3]$ .
In the $4$ -th operation, $a_2 < a_3$ , after the operation, $a_3 = 0$ . Now the sequence $a$ is $[0,0,0]$ .
So the minimum number of operations is $4$ .
In the $1$ -st operation, $a_1 < a_2$ , after the operation, $a_2 = a_1 = 1$ . Now the sequence $a$ is $[1,1,3]$ .
In the $2$ -nd operation, $a_1 = a_2 = 1$ , after the operation, $a_1 = 0$ . Now the sequence $a$ is $[0,1,3]$ .
In the $3$ -rd operation, $a_1 < a_2$ , after the operation, $a_2 = 0$ . Now the sequence $a$ is $[0,0,3]$ .
In the $4$ -th operation, $a_2 < a_3$ , after the operation, $a_3 = 0$ . Now the sequence $a$ is $[0,0,0]$ .
So the minimum number of operations is $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted