题意:给你n个数,进行*2,/2操作,求解最小操作次数能使所有数相同。

思路:因为数值在100000以内,直接枚举过去,对读入的每一个数,模拟操作,用数组s来存放累计操作步数,数组flag用来标记确



定*和/分开操作,最后模拟完,只要判断出s数组里面最小的操作步数即可

#include <iostream>
#include <stdio.h>
#define MAX 99999999
#define N 100010
using namespace std; int i,flag[N],s[N],c[N]; void solve(int x, int ti)
{
if(x>100000||flag[x]==i)
return;
flag[x]=i;
s[x]+=ti;
c[x]++;
solve(2*x,ti+1);
solve(x/2,ti+1);
} int main()
{
int n,a,ans=MAX;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
solve(a, 0);
}
for(int j=0;j<=100000;j++)
if(c[j]==n)
ans=min(ans,s[j]);
printf("%d",ans);
return 0;
}

Codeforces-Div312的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

  10. CodeForces - 453A Little Pony and Expected Maximum

    http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...

随机推荐

  1. Josephus

    利用循环链表模拟约瑟夫问题,把自杀的人的顺序排列出来 代码如下: #include<stdio.h> #include<stdlib.h> typedef int status ...

  2. Kendo UI for Angular 2 控件

    Kendo UI for Angular 2 控件 伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免 ...

  3. codeforces D. Painting The Wall

    http://codeforces.com/problemset/problem/399/D 题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色.现在随机选中一块进行涂色(如 ...

  4. tortoisegit安装使用

    git的使用越来越广泛 使用命令比较麻烦,下面讲解一下tortoisegit的使用 先下载安装git(msysgit)和tortoisegit,安装后提示重启电脑,不解释 1.找一个文件夹做仓库 这里 ...

  5. COJ 2004 序列

    传送门:http://oj.cnuschool.org.cn/oj/home/addSolution.htm?problemID=978 试题描述: WZJ的数字游戏又开始了.他写了N个自然数Ai到黑 ...

  6. WordPress Duplicator 0.4.4 Cross Site Scripting

    测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! Advisory ID: HTB23162 Product:DuplicatorWordPressPlugin Vend ...

  7. 安装zabbix2.2.3

    系统版本:CentOS 6.3_x86_64 zabbix版本:zabbix-2.2.3 zabbix服务端IP:172.16.10.72 1.yum安装LAMP环境 # yum -y install ...

  8. POJ 3468 A Simple Problem with Integers(详细题解) 线段树

    这是个线段树题目,做之前必须要有些线段树基础才行不然你是很难理解的. 此题的难点就是在于你加的数要怎么加,加入你一直加到叶子节点的话,复杂度势必会很高的 具体思路 在增加时,如果要加的区间正好覆盖一个 ...

  9. page-object使用(1)

    创建你的page 你必须做的第一件事情是创建你的page,这是一些包含了PageObject模块的简单的ruby类,请不要创建你自己的initialize方法,因为已经有一个存在而且不能被覆盖.如果你 ...

  10. cf703B Mishka and trip

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input  standard ...