2018第一届东电智能科技竞赛:决赛—C语言程序补全题

………………决赛是抢答模式,居然出了道英文题?!!一时半会看不懂题,划水队终于划不动了。

这是一道codeforce上的题目,579A    Raising Bacteria

题目描述

        You are a lover of bacteria. You want to raise some bacteria in a box.

Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.

        What is the minimum number of bacteria you need to put into the box across those days?

        输入输出均为一个整数。

#include<stdio.h>
int main(int argc,char* argv[])
{
    int n,cnt=0;
    scanf("%d",&n);
    
    /* 补全 */
        
    printf("%d\n",cnt);
    return 0;
}

        题目大致是说一个细菌一天可以分裂成两个,输入希望培养出几个细菌,然后输出在这些天里最少需要放几个细菌?

没有给输入输出的样例,这就很麻烦…哪一天放细菌都可以,也就是说一天放一个最划算。要求的就是输入的数二进制形式有几个 1 ,显然边计数边右移啊。

/* 补全处 */
while(n)
{
    n&1?cnt++:cnt;
    n>>=1;
}
END

猜你喜欢

转载自blog.csdn.net/belous_zxy/article/details/80561358