题目链接:http://codeforces.com/problemset/problem/558/C

题意:把n个数变成相同所需要走的最小的步数
易得到结论,两个奇数不同,一直×2不可能有重叠
枚举每个数可能到得所有值,以及统计达到该值的时候已经走的步数
最终答案就是1到up中num[i]最小的数

Examples
input output
2 input output
5 Note
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 . 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 .

***********************************************************

AC代码:

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stdlib.h> using namespace std; #define N 5200
#define INF 0x3f3f3f3f
#define Maxn 100010 int a[Maxn],step[Maxn],num[Maxn]; int main()
{
int n,i; while(scanf("%d", &n) != EOF)
{
memset(step,,sizeof(step));
memset(num,,sizeof(num)); for(i=; i<=n; i++)
scanf("%d", &a[i]); for(i=; i<=n; i++)
{
int x=a[i],sc=; while(x)
{
int s1=;
while(x%==)
{
x/=;
s1++;
} int y=x,s2=;
while(y<=Maxn)
{
num[y]++;
step[y]+=sc+abs(s1-s2);
s2++;
y*=;
} sc+=s1+;
x/=;
}
}
int ans=INF;
for(i=;i<=Maxn;i++)
if(num[i]==n)
ans=min(ans,step[i]); printf("%d\n", ans);
}
return ;
}

这个里写的很清楚:http://blog.csdn.net/u014028317/article/details/46897963

codeforces 558/C Amr and Chemistry(数论+位运算)的更多相关文章

  1. CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)

    Codeforces 558C 题意:给n个数字,对每一个数字能够进行两种操作:num*2与num/2(向下取整),求:让n个数相等最少须要操作多少次. 分析: 计算每一个数的二进制公共前缀. 枚举法 ...

  2. CF 558 C. Amr and Chemistry 暴力+二进制

    链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second ...

  3. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. codeforces 558C C. Amr and Chemistry(bfs)

    题目链接: C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力

    Magic Forest 题意:就是在1 ~ n中找三个值,满足三角形的要求,同时三个数的异或运算还要为0: , where  denotes the bitwise xor of integers  ...

  6. 暴力 + 贪心 --- Codeforces 558C : Amr and Chemistry

    C. Amr and Chemistry Problem's Link: http://codeforces.com/problemset/problem/558/C Mean: 给出n个数,让你通过 ...

  7. 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/ ...

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

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

  9. Codeforces 558C Amr and Chemistry 暴力 - -

    点击打开链接 Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. sql身份证号查人数

    select a.*,b.item_name from (select sum(buy_num) num,nqh from (select substr(a.embed_dis_province,1, ...

  2. 项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】

    在上一篇教程项目管理实践[三]每日构建[Daily Build Using CruiseControl.NET and MSBuild] 中,我们讲解了如何使用CCNET+MSBuild来自动编译项目 ...

  3. 转:java.io.IOException: Exceeeded maximum number of redirects: 5 解决版本

    Jmeter运行的时候出现的重定向超过n次的问题: When trying to test a Silverlight application, I get the below error. Has ...

  4. Logger日志管理工具类

    import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...

  5. Java 微信登录授权后获取微信用户信息昵称乱码问题解决

    String getUserInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+access_toke ...

  6. 部署php项目

    1.不写端口号,即127.0.0.1,其隐含一个默认端口号80 2.查看当前占用的端口号 3.nginx修改工作路径,nginx修改端口号 4.查看端口号是否可访问telnet命令 在dos界面输入命 ...

  7. Python第三方库安装技巧

    pytho下有三种安装第三方库方法: 1.通过easy_install安装 2.通过Pip安装 前面两种,由于受国内部门网站原因,如果安装失败,可采用接下来的第三种方法 3.在指定网站下载安装 第三方 ...

  8. leetcode383

    已知两个字符串,然后比较一个字符串是否来自另一个字符串,没有顺序要求. 简单题,用一个数组保存前一个字符串的每一个字符出现的次数,然后循环后一个字符串去检查,如果次数不够了,那么就返回false pu ...

  9. Python识别网站验证码

    http://drops.wooyun.org/tips/6313 Python识别网站验证码 Manning · 2015/05/28 10:57 0x00 识别涉及技术 验证码识别涉及很多方面的内 ...

  10. HDU2502:月之数

    Problem Description 当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数. 如果一个正整数m表示成二进制,它的位数为n(不 ...