CF1615A.Closing The Gap
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n block towers in a row, where tower i has a height of ai. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:
- Choose two indices i and j (1≤i,j≤n; i=j), and move a block from tower i to tower j. This essentially decreases ai by 1 and increases aj by 1.
You think the ugliness of the buildings is the height difference between the tallest and shortest buildings. Formally, the ugliness is defined as max(a)−min(a).
What's the minimum possible ugliness you can achieve, after any number of days?
一行中有 n 座积木塔,其中第 i 座塔的高度为 ai。你是一名建筑队的成员,希望让这些建筑看起来尽可能美观。在一天内,你可以执行以下操作:
- 选择两个下标 i 和 j(满足 1≤i,j≤n 且 i=j),并将一个积木块从第 i 座塔移动到第 j 座塔。该操作实质上使 ai 减少 1,同时使 aj 增加 1。
你认为建筑的“丑陋度”等于最高塔与最矮塔之间的高度差。形式化地,丑陋度定义为 max(a)−min(a)。
在经过任意天数的操作后,你能达到的最小可能丑陋度是多少?
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases. Then t cases follow.
The first line of each test case contains one integer n (2≤n≤100) — the number of buildings.
The second line of each test case contains n space separated integers a1,a2,…,an (1≤ai≤107) — the heights of the buildings.
第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(2≤n≤100),表示建筑物的数量。
每个测试用例的第二行包含 n 个以空格分隔的整数 a1,a2,…,an(1≤ai≤107),表示各建筑物的高度。
输出格式
For each test case, output a single integer — the minimum possible ugliness of the buildings.
对于每个测试用例,输出一个整数——建筑物的最小可能丑陋度。
输入输出样例
输入#1
3 3 10 10 10 4 3 2 1 2 5 1 2 3 1 5
输出#1
0 0 1
说明/提示
In the first test case, the ugliness is already 0.
In the second test case, you should do one operation, with i=1 and j=3. The new heights will now be [2,2,2,2], with an ugliness of 0.
In the third test case, you may do three operations:
- with i=3 and j=1. The new array will now be [2,2,2,1,5],
- with i=5 and j=4. The new array will now be [2,2,2,2,4],
- with i=5 and j=3. The new array will now be [2,2,3,2,3].
The resulting ugliness is 1. It can be proven that this is the minimum possible ugliness for this test.
在第一个测试用例中,丑陋度已经是 0。
在第二个测试用例中,你需要执行一次操作,其中 i=1 且 j=3。新的高度数组将变为 [2,2,2,2],丑陋度为 0。
在第三个测试用例中,你可以执行三次操作:
- 取 i=3 且 j=1,新数组变为 [2,2,2,1,5];
- 取 i=5 且 j=4,新数组变为 [2,2,2,2,4];
- 取 i=5 且 j=3,新数组变为 [2,2,3,2,3]。
最终的丑陋度为 1。可以证明,这是该测试用例所能达到的最小丑陋度。
输入解题思路,AI测评打分。不知道怎么写?