Codeforces Round #312 (Div. 2)-C. AMR and Chemistry

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.