zoukankan      html  css  js  c++  java
  • CF579

    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?

    Input

    The only line containing one integer x (1 ≤ x ≤ 109).

    Output

    The only line containing one integer: the answer.

    Examples

    Input
    5
    Output
    2
    Input
    8
    Output
    1

    Note

    For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.

    For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.

    题解:水题;

    参考代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cstdlib>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<deque>
     9 #include<stack>
    10 #include<set>
    11 #include<vector>
    12 #include<map>
    13 using namespace std;
    14 typedef long long LL;
    15 typedef pair<int,int> PII;
    16 #define PI acos(-1)
    17 #define EPS 1e-8
    18 const int INF=0x3f3f3f3f;
    19 const LL inf=0x3f3f3f3f3f3f3f3fLL;
    20 const int maxn=1e5+10;
    21 
    22 int main()
    23 {
    24     int n;
    25     while(~scanf("%d",&n))
    26     {
    27         int cnt=0;
    28         for(int t=1;t<=n;t*=2)
    29         {
    30             if((t&n)!=0) cnt++,n-=t;
    31         } 
    32         printf("%d
    ",cnt); 
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    [C4] 前馈神经网络(Feedforward Neural Network)
    [C3] 正则化(Regularization)
    [C2] 逻辑回归(Logistic Regression)
    [C1] 线性回归(Linear Regression)
    Python基础学习
    装饰器
    完全理解Python迭代对象、迭代器、生成器
    django自己搭建的博客
    git学习,哇瑟说实话我想要的
    类继承和多态,子类重写构造函数,多重继承学习
  • 原文地址:https://www.cnblogs.com/csushl/p/9520420.html
Copyright © 2011-2022 走看看