CF1678A.Tokitsukaze and All Zero Sequence

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tokitsukaze has a sequence aa of length nn. For each operation, she selects two numbers aia_i and aja_j (i≠ji \ne j; 1≤i,j≤n1 \leq i,j \leq n).

  • If ai=aja_i = a_j, change one of them to 00.
  • Otherwise change both of them to min⁡(ai,aj)\min(a_i, a_j).

Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to 00. It can be proved that the answer always exists.

Tokitsukaze 有一个长度为 nn 的序列 aa。每次操作中,她选择两个数 aia_i 和 aja_j(其中 i≠ji \ne j,且 1≤i,j≤n1 \leq i,j \leq n):

  • 若 ai=aja_i = a_j,则将其中一个改为 00;
  • 否则,将二者均改为 min⁡(ai,aj)\min(a_i, a_j)。

Tokitsukaze 想知道:将序列中所有数变为 00 所需的最少操作次数是多少?可以证明答案一定存在。

输入格式

The first line contains a single positive integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

For each test case, the first line contains a single integer nn (2≤n≤1002 \leq n \leq 100) — the length of the sequence aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1000 \leq a_i \leq 100) — the sequence aa.

第一行包含一个正整数 tt(1≤t≤10001 \leq t \leq 1000)—— 表示测试用例的数量。

对于每个测试用例,第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100)—— 表示序列 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1000 \leq a_i \leq 100)—— 表示序列 aa。

输出格式

For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to 00.

对于每个测试用例,输出一个整数——将序列中所有数字变为 00 所需的最少操作次数。

输入输出样例

  • 输入#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 00:

In the 11-st operation, a1<a2a_1 \lt a_2, after the operation, a2=a1=1a_2 = a_1 = 1. Now the sequence aa is [1,1,3][1,1,3].

In the 22-nd operation, a1=a2=1a_1 = a_2 = 1, after the operation, a1=0a_1 = 0. Now the sequence aa is [0,1,3][0,1,3].

In the 33-rd operation, a1<a2a_1 \lt a_2, after the operation, a2=0a_2 = 0. Now the sequence aa is [0,0,3][0,0,3].

In the 44-th operation, a2<a3a_2 \lt a_3, after the operation, a3=0a_3 = 0. Now the sequence aa is [0,0,0][0,0,0].

So the minimum number of operations is 44.

在第一个测试用例中,将序列中所有数字变为 00 的一种可能方式如下:

第 11 次操作:a1<a2a_1 \lt a_2,操作后 a2=a1=1a_2 = a_1 = 1。此时序列 aa 变为 [1,1,3][1,1,3]。

第 22 次操作:a1=a2=1a_1 = a_2 = 1,操作后 a1=0a_1 = 0。此时序列 aa 变为 [0,1,3][0,1,3]。

第 33 次操作:a1<a2a_1 \lt a_2,操作后 a2=0a_2 = 0。此时序列 aa 变为 [0,0,3][0,0,3]。

第 44 次操作:a2<a3a_2 \lt a_3,操作后 a3=0a_3 = 0。此时序列 aa 变为 [0,0,0][0,0,0]。

因此,最少操作次数为 44。

输入解题思路,AI测评打分。不知道怎么写?

首页