平均n瓶化学试剂

 

 

#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdlib.h>
#include <iostream>
#include <vector>
#include <queue>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<iostream>
using namespace std;

int main()
{
	int m, n;
	int maxx=100000;
	int a, b[100000]={0}, c[100000]={0};
    cin>>n;
    for (int i=1; i <= n; i++){
    	cin>>a;
    	c[a]++;
    	int divide=a;
    	int mul=a;
    	for(int j=1;j<=log(100000/a)/log(2);j++){
    		if(divide>1){
    			divide=divide/2;
    			b[divide]+=j;
    			c[divide]++;
			}
			mul=mul*2;
    		b[mul]+=j;
    		c[mul]++;
//    		cout<<111<<endl;
		} 
	}
	int min=maxx;
	for (int i=0; i <= maxx; i++){
//		cout<<i<<' '<<c[i]<<' '<<b[i]<<endl;
    	if(c[i]==n){
    		if(b[i]<min){
    			min=b[i];
			} 
		}
	}
	cout<<min;
	
    return 0;
}
/*

3
4 8 2

3
3 5 6

*/

 

展开阅读全文

没有更多推荐了,返回首页