shtilabys

导航

#838 div 2

第一条  A. Divide and Conquer

题目描述:

An array bb is good if the sum of elements of bb is even.

You are given an array aa consisting of nn positive integers. In one operation, you can select an index ii and change ai:=ai2ai:=⌊ai2⌋. 

Find the minimum number of operations (possibly 00) needed to make aa good. It can be proven that it is always possible to make aa good.

† x⌊x⌋ denotes the floor function — the largest integer less than or equal to xx. For example, 2.7=2⌊2.7⌋=2, π=3⌊π⌋=3 and 5=5⌊5⌋=5.

没什么好说的

纯模拟

#include<bits/stdc++.h>
using namespace std;
int a[10000000];
int b[10000000];
int m=0;
int ss(int n)
{
    int i=0;
    while(n%2!=0)
    {
        i++;
        n=n/2;
    }
    return i;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            b[i]=1000000;
            m=0;
            int h;
            cin>>h;
            for(int j=1;j<=h;j++)
                {
                    cin>>a[j];
                    m+=a[j];
                    if(a[j]%2==0)
                        {
                            int jj=0;
                            while(a[j]%2!=1)
                                {
                                    jj++;
                                    a[j]=a[j]/2;
                                    }    
                            b[i]=min(b[i],jj);        
                        }
                    else{
                        b[i]=min(b[i],ss(a[j]));
                    }
                }
            if(m%2==0)
            {
              b[i]=0;
            }
        
        }
    for(int i=1;i<=n;i++)
        cout<<b[i]<<endl;
    return 0;
}

问题在于,我那天把b数组开小了

导致我一直过不了,草,硬是一条没做出来

就很崩溃

之后的题有时间再想

posted on 2022-12-16 13:13  exldiposen  阅读(13)  评论(0)    收藏  举报