Codeforces 558/c AMR and Chemistry

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/558/C

Test instructions: Change n number to the same minimum number of steps required to go
Easy to get the conclusion that two odd numbers are different and have been x2 impossible to overlap
Enumerate the possible values of each number and the number of steps that have been taken when the value is reached
The final answer is 1 to up num[i] the smallest number

Examplesinput34 8 2Output2

input33 5 6Output5

Notein The first sample test, the optimal solution isTo divide the second chemical volume by both, and multiply the third chemical volume by both to make all the volumes equal4. In the second sample test, the optimal solution isTo divide the first chemical volume by A and divide the second and the third chemical volumes by both twice to do all The volumes equal1.

***********************************************************

AC Code:

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5#include <iostream>6#include <queue>7#include <map>8#include <stdlib.h>9 Ten using namespacestd; One  A #defineN 5200 - #defineINF 0x3f3f3f3f - #defineMAXN 100010 the  - intA[MAXN],STEP[MAXN],NUM[MAXN]; -  - intMain () + { -     intn,i; +  A      while(SCANF ("%d", &n)! =EOF) at     { -memset (step,0,sizeof(step)); -memset (NUM,0,sizeof(num)); -  -          for(i=1; i<=n; i++) -scanf"%d", &a[i]); in  -          for(i=1; i<=n; i++) to         { +             intX=a[i],sc=0; -  the              while(x) *             { $                 ints1=0;Panax Notoginseng                  while(%2==0) -                 { theX/=2; +s1++; A                 } the  +                 intY=x,s2=0; -                  while(y<=MAXN) $                 { $num[y]++; -Step[y]+=sc+abs (s1-S2); -s2++; they*=2; -                 }Wuyi  thesc+=s1+1; -X/=2; Wu             } -         } About         intans=INF; $          for(i=1; i<=maxn;i++) -             if(num[i]==N) -ans=min (ans,step[i]); -  Aprintf"%d\n", ans); +     } the     return 0; -}

Codeforces 558/c AMR and Chemistry

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.