Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力
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 暴力的更多相关文章
- Codeforces Round #312 (Div. 2) C.Amr and Chemistry
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...
- 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 ...
- 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. ...
- 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 ...
- 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 ...
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- Codeforces Round #312 (Div. 2)
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...
- 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 ...
- 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 ...
随机推荐
- JQuery实现分页程序代码,源码下载
Web开发,分页在所难免的,微软GridView.AspPager等设置分页数据可以自动分页,但是这里浏览器会闪动,用户体验不是很友好,在此我整理了JQuery实现分页,并且使用 JQuery模板显示 ...
- devexpress datagrid 与imageEdit以及如何存图片到数据库 z
http://blog.csdn.net/haoyujie/article/details/41277703 首先建立了一个数据库的表,这个表中,有一个字段是image类型(SQL Server数据库 ...
- 职业操盘手内部教材 z
重 点抢筹区: 是主力机构在低位拉高建仓后的一个相当尴尬的区域!因为在这个区域,场外的绝大多数投资者不敢买,而场内持有的人却很想卖!所以会出现成片的卖盘挂单! 由于主力向上做的意图已经非常明显,所 ...
- Golang做的验证码(2)
前面一篇文章介绍了2个用Golang做的验证码 http://www.cnblogs.com/ghj1976/p/3392847.html 这里再补充几个: 1.在GAE上使用的Google的验证码 ...
- 【Linux】一个简单的线程创建和同步的例子
最近很多精力在Linux上,今天简单看了一下Linux上的线程和同步,其实不管windows还是Linux,OS层面的很多原理和概念都是相同的,很多windows之上的经验和概念完全可以移植到Linu ...
- InputFormat 总结
在mr中的输入类,常见的InputFormat是TextInputFormat,也是mr默认的文件处理类,处理普通文本文件,作用是 1 每一行作为一个记录,将每一行在文件中的起始偏移量做为key,内容 ...
- SQL存儲過程的調試方法
1.在vs2010调试存储过程步骤如下:(要點:連接登陸賬號的權限必須是管理員,才能單步調試,否則只能直接執行存儲過程:[因此,此方式適合數據庫和vs裝在同一台電腦上]) 1.1首先,打开vs,点击 ...
- IOS平台设计规范
一.UI的控件概述: 1.框架UI的元素分为4类: A:栏:状态栏目和导航栏的结合体; B:内容视图:应用显示的内容信息,包括相关的交互行为,例如滚屏.插入.删除等操作进行排序; C:控制元素:产品行 ...
- Determining IP information for eth0... failed; no link present. Check cable?
在RedHat下重启网络,service network restart之后,出现问题 Determining IP information for eth0... failed; no link p ...
- Maven,预加载资源文件
预加载资源文件需要先启用功能: <build> <resources> <resource> <directory>src/main/resources ...