C. Amr and Chemistry

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/558/problem/C

Description

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 ai 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 2ai
    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?

Input

The first line contains one number n (1 ≤ n ≤ 105), the number of chemicals.

The second line contains n space separated integers ai (1 ≤ ai ≤ 105), representing the initial volume of the i-th chemical in liters.

Output

Output one integer the minimum number of operations required to make all the chemicals volumes equal.

Sample Input

3
4 8 2

Sample Output

2

HINT

题意

给你一个序列,你有俩操作,可以使得一个数乘以2,也可以使得一个数除以2

然后问你最少进行多少个操作,可以使得所有数都一样

题解:

直接暴力跑就好了,但是这里有一个人问题,比如5/2=2 2×2=4,这样就不一样了怎么办?

一样暴力就好了,当出现奇数的时候,直接暴力乘以2网上爬

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int cnt[maxn],num[maxn];
int a[maxn];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
int x=read();
int pre=;
while(x)
{
int s=;
while(x%==)
{
x/=;
s++;
}
int y=x;
int j=;
while(y<maxn)
{
cnt[y]++;
num[y]+=pre+abs(j-s);
j++;
y*=;
}
pre+=s+;
x/=;
}
}
int ans=inf;
for(int i=;i<maxn;i++)
{
if(cnt[i]==n)
ans=min(ans,num[i]);
}
cout<<ans<<endl;
}

Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力的更多相关文章

  1. Codeforces Round #312 (Div. 2) C.Amr and Chemistry

    Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...

  2. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  3. Codeforces Round #312 (Div. 2) B.Amr and The Large Array

    Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...

  4. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  5. C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)

    C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #312 (Div. 2) ABC题解

    [比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...

  7. Codeforces Round #312 (Div. 2)

    好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...

  8. B. Amr and The Large Array(Codeforces Round #312 (Div. 2)+找出现次数最多且区间最小)

    B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力

    A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...

随机推荐

  1. location.hash来保持页面状态

    /*本例是为了在客户端页面返回时保存状态,采用hash值记录的模式,为了使用方便所写的存取hash值的库,时间仓促,望指出错误.*/var pageStateHash = { hashArray: [ ...

  2. 开源堡垒机GateOne的安装、配置笔记

    因为内部临时需要这么一套系统,所以搜搜查查,搞定了系统部署,使用pam认证的配置. 系统初始化是使用CentOS 6.5 Mini x64版本.   首先exports http_proxy和http ...

  3. python代码编程规范

    一.内容格式 1.注释部分:模块名及简介(一般用一行写完),模块描述(包含各类方法),其它描述(注意点,功能,示例等,可以分多段) 2.导入模块:Import XXX 3.全局变量定义:wantobj ...

  4. unity3d Human skin real time rendering 真实模拟人皮实时渲染(转)

    先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成 ...

  5. PHP 关于回调的用法

    class aClass { public static function directWrite($message) { echo 'this is a static function from a ...

  6. mybatis源码学习: 编译的方法

    mybatis3用了一段时间,抽出时间来研究一下.具体用法参考官方文档就行,源码在这里.mybatis相对而言,规模较小,可以从中学习如何编写高质量的java项目. mybatis3使用maven管理 ...

  7. 使用ncc分析代码

    1 ncc是一个编译器, 用于输出程序的一些调用信息等, 可以查看函数调用关系, 支持函数指针, 查看数据结构和代码. 可以用来分析和理解代码. “" ... with ncc, in le ...

  8. Azure Cloud中的Log4Net设置

    这里的Cloud包含Worker Role和Web Role,Role是运行在云主机中的,这里的主机和VM有所不同,Windows Azure Role Architecture.我们并没有和本地服务 ...

  9. ubuntu LVM

    本文介绍下,在ubuntu中扩展LVM磁盘的具体方法,有需要的朋友参考下吧. 当LV空间利用率较大即将耗尽LV空间时,可以将一块新的磁盘或一块磁盘上的/空间加入LV中. 现在/ 空间如下: 代码示例: ...

  10. 第三百二十六天 how can I 坚持

    今天元宵节啊,晚上去蓝色港湾看了看灯光节,快冻死了,人倒是挺多. 其他没啥了. 还有晚上吃了几个元宵. 好像冻感冒了,有点头晕. 睡觉.