CF558C.Amr and Chemistry
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.
Amr has n different types of chemicals. Each chemical i has an initial volume of a__i liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.
To do this, Amr can do two different kind of operations.
- Choose some chemical i and double its current volume so the new volume will be 2_a__i_
- Choose some chemical i and divide its volume by two (integer division) so the new volume will be

Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?
阿米尔热爱化学,尤其喜欢做实验。他正在为一个新奇有趣的实验做准备。
阿米尔有 n 种不同的化学物质。每种化学物质 i 的初始体积为 ai 升。在本次实验中,阿米尔需要将所有化学物质混合在一起,但必须先使所有化学物质的体积相等。因此,他的任务是让所有化学物质的体积变得相同。
为此,阿米尔可以执行以下两种操作之一:
- 选择某种化学物质 i,将其当前体积翻倍,即新体积变为 2ai;
- 选择某种化学物质 i,将其体积除以 2(整数除法),即新体积变为

假设每种化学物质都盛放在容积无限大的容器中。现在阿米尔想知道:使所有化学物质体积相等所需的最少操作次数是多少?
输入格式
The first line contains one number n (1 ≤ n ≤ 105), the number of chemicals.
The second line contains n space separated integers a__i (1 ≤ a__i ≤ 105), representing the initial volume of the i-th chemical in liters.
第一行包含一个整数 n(1≤n≤105),表示化学药品的数量。
第二行包含 n 个用空格分隔的整数 ai(1≤ai≤105),表示第 i 种化学药品的初始体积(单位:升)。
输出格式
Output one integer the minimum number of operations required to make all the chemicals volumes equal.
输出一个整数,表示使所有化学品体积相等所需的最少操作次数。
输入输出样例
输入#1
3 4 8 2
输出#1
2
输入#2
3 3 5 6
输出#2
5
说明/提示
In the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal 4.
In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal 1.
在第一个样例测试中,最优解是将第二种化学物质的体积除以 2,并将第三种化学物质的体积乘以 2,从而使所有体积均变为 4。
在第二个样例测试中,最优解是将第一种化学物质的体积除以 2,并将第二、三种化学物质的体积各自连续除以 2 两次,从而使所有体积均变为 1。
输入解题思路,AI测评打分。不知道怎么写?