CF2232A.Convergence
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice is inviting her friends to a party to eat cakes. However, each friend may not be at the same place, so everyone has to meet up at the same location first.
Alice has n friends, where the i-th friend is at position ai. To make everyone be at the same place, Alice has to make multiple group calls. Unfortunately, the signal is weak, and Alice can only call 2 other people at a time.
Being a good person, Alice doesn't want her friends to walk too far. So, for each group call containing the i-th friend and the j-th friend, Alice will tell both of them to meet at some integer location between min(ai,aj) and max(ai,aj) inclusive. After that, both of them will move to that location so quickly that Alice cannot make any group call during their movement. Please note that Alice can call these friends again once they reach that location.
The party is starting soon, so Alice needs to make group calls fast. Help her find the minimum number of group calls she needs to make.
爱丽丝正在邀请她的朋友们参加一个吃蛋糕的派对。然而,每位朋友可能身处不同地点,因此大家必须先在同一个地点集合。
爱丽丝有 n 位朋友,其中第 i 位朋友位于位置 ai。为了让所有人最终聚集于同一地点,爱丽丝需要发起多次群组通话。不幸的是,信号较弱,爱丽丝每次只能同时呼叫另外 2 人。
作为一位体贴的人,爱丽丝不希望朋友们步行过远。因此,在每一次包含第 i 位朋友和第 j 位朋友的群组通话中,爱丽丝会指定一个位于 min(ai,aj) 与 max(ai,aj)(含端点)之间的整数位置,让这两位朋友都前往该处汇合。随后,他们将立即动身前往该位置,且移动过程极快,以至于爱丽丝在此期间无法发起任何新的群组通话。请注意:一旦这两位朋友抵达该位置,爱丽丝便可再次呼叫他们(包括彼此或他人)。
派对即将开始,爱丽丝需要尽快完成所有群组通话。请帮她找出所需的最少群组通话次数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤100) — the number of friends Alice has.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the locations of her friends.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤100)—— 表示爱丽丝拥有的朋友数量。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 表示她朋友们的位置。
输出格式
For each test case, output the minimum number of group calls she needs to make in order for all of her friends to be in the same location.
对于每个测试用例,输出她需要发起的最少群组通话次数,使得她所有的朋友都位于同一位置。
输入输出样例
输入#1
4 5 1 2 3 4 5 5 1 1 1 2 2 11 3 1 4 1 5 9 2 6 5 3 5 5 1 2 2 2 2
输出#1
2 2 5 1
说明/提示
In the first test case, the minimum number of group calls is 2. One way to make everyone at the same location is as follows:
- Call the 1-st and 4-th friend and tell them to move to location 3. Their locations are now [3,2,3,3,5].
- Call the 2-nd and 5-th friend and tell them to move to location 3. Their locations are now [3,3,3,3,3].
In the second test case, the minimum number of group calls is 2. One way to make everyone at the same location is as follows:
- Call the 1-st and 4-th friend and tell them to move to location 1. Their locations are now [1,1,1,1,2].
- Call the 4-th and 5-th friend and tell them to move to location 1. Their locations are now [1,1,1,1,1].
在第一个测试用例中,最少的群组通话次数为 2。一种使所有人到达同一位置的方法如下:
- 召集第 1 位和第 4 位朋友,并告知他们移动到位置 3。此时他们的位置变为 [3,2,3,3,5]。
- 召集第 2 位和第 5 位朋友,并告知他们移动到位置 3。此时他们的位置变为 [3,3,3,3,3]。
在第二个测试用例中,最少的群组通话次数为 2。一种使所有人到达同一位置的方法如下:
- 召集第 1 位和第 4 位朋友,并告知他们移动到位置 1。此时他们的位置变为 [1,1,1,1,2]。
- 召集第 4 位和第 5 位朋友,并告知他们移动到位置 1。此时他们的位置变为 [1,1,1,1,1]。
输入解题思路,AI测评打分。不知道怎么写?