题目链接: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. erlang分布式编程模型

    erlang分布式编程有两种模型 一.分布式erlang 运行在可信的网络环境中 1.rpc提供的远程过程调用 rpc:call(Node,Mode,Fun,Args) ->Result|{ba ...

  2. 第2章 熟悉Eclipse开发工具----加减乘除,和差积商的英文写法

    加减乘除表示运算:plus  minus multiply divide和差积商表示运算结果:sum difference product quotient

  3. ural 1119. Metro(动态规划)

    1119. Metro Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to ...

  4. Android状态选择器用法总结

    原创文章,转载请注明出处http://www.cnblogs.com/baipengzhan/p/6284682.html 本文首先列出常见状态选择器的创建,然后按照常用控件来分别列出状态选择器的具体 ...

  5. leetcode83,删除有序链表中的重复元素

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  6. hdu_4046_Panda(树状数组)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 题意:一大堆篇幅介绍,跳过直奔主题,让你寻找给定区间的“wbw”的个数. 题解:直接上树状数组, ...

  7. hdu_1011_Starship Troopers(树形DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1011 题意:有N个房间,房间的连通性为树形的,就是说你要占领子结点,必须要先占领 父结点,每个房间有第 ...

  8. 裸二分图匹配poj1469

    poj1496 题意: 给你p门课程和n个学生,一个学生可以选0门,1门,或者多门课程, 现在要求一个由p个学生组成的集合,满足下列2个条件: 1.每个学生选择一个不同的课程 2.每个课程都有不同的代 ...

  9. lldpcli 常用命令

    1.查看周围的邻居列表 root@hbg:/# lldpcli show neighbors------------------------------------------------------ ...

  10. %02d

    %d表示打印整型的,%2d表示把整型数据打印最低两位,%02d表示把整型数据打印最低两位,如果不足两位,用0补齐所以打印出来就是02了