CF 579A (二进制拆分)
在培养皿中,每个细胞每天会繁殖,数量*2
我们可以在任意天加入任意数量的细胞入培养皿中。
想要知道最少加入多少个细胞,可以使得有一天,培养皿中细胞的数量会恰好为x
其实就是输出X的二进制中有多少个1
Sample test(s)
input
5
output
2
input
8
output
1
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <string> 6 # include <cmath> 7 # include <queue> 8 # include <list> 9 # define LL long long 10 using namespace std ; 11 12 13 14 int main() 15 { 16 //freopen("in.txt","r",stdin) ; 17 int n ; 18 while(scanf("%d",&n) != EOF) 19 { 20 int sum = 0 ; 21 while(n) 22 { 23 if (n & 1) 24 sum++ ; 25 n >>= 1 ; 26 } 27 printf("%d\n" , sum) ; 28 } 29 30 31 32 return 0; 33 }