/*Test Instructions: There are n chemical agents, the capacity of the AI, given N and their capacity. There are two types of operations available: 1. Choose a potion to change its capacity to 2*ai 2. Select a medicament to change its capacity to AI/2 the minimum number of operands makes each reagent equal in capacity. Problem solving: Find out the number of each number that can be changed by the two operations, using the F array to record the number of times. Use the V array to record how many steps this number took. Then the number of N in the F array (that is, each number can be transformed into this number) is the number that is likely to become. The one with the least number of steps is the answer. Because the number of unequal is no way by 2 to become the same, so to the top of the time to the MX can be. If there is an odd number in the process, then it will have new numbers in addition to 2 and multiply by 2, so you have to go to the top again and then down. */#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespacestd;Const intMAXN =1000005;intF[MAXN],V[MAXN],A[MAXN];intMain () {intN,ans = 1e9,mx=0; scanf ("%d",&N); for(intI=0; i<n;i++) {scanf ("%d", &a[i]); MX =Max (mx,a[i]); } for(intI=0; i<n;i++) { intj = A[i], TMP =0; intSTP =0, STP2 =0; F[J]++; while(J <mx) {J*=2; f[j]++; STP++; V[J] + =STP; } J=a[i]; STP =0; while(J >0) { if(j&1&& j!=1) {J>>=1; f[j]++ ; STP++; V[J] + =STP; STP2= STP; TMP =J; while(TMP <mx) {tmp= tmp<<1; stp2++; F[TMP]++; V[TMP] + =STP2; } } Else{J= j>>1; stp++; F[J]++; V[J] + =STP; } } } for(intI=1; i<mx*2; i++) { if(f[i]==n) ans =min (ans,v[i]); } cout<<ans<<Endl; return 0;}
Codeforces Round #312 (Div. 2)-C. AMR and Chemistry