Raising Bacteria CodeForces - 579A
来源:互联网 发布:刷网游金币软件 编辑:程序博客网 时间:2024/05/18 02:08
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 exactlyx bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
The only line containing one integer x (1 ≤ x ≤ 109).
The only line containing one integer: the answer.
5
2
8
1
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be4 bacteria in the box. Now we put one more resulting5 in the box. We added2 bacteria in the process so the answer is2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be8 in the box. So the answer is1.
此题看似不是很简单,但是可以想到,已知细菌时2的指数增长,就像位运算,2的n次方也就像是二进制的形式,就像8就是1转化为二进制为1000,5就是101与题目的描述一个意思差不多
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){ int n,cou; while(~scanf("%d",&n)) { cou=0; while(n) { if(n%2==1) { cou++; } n/=2; } printf("%d\n",cou); } return 0;}
- CodeForces 579A - Raising Bacteria
- CodeForces 579A Raising Bacteria
- codeforces 579A Raising Bacteria
- Raising Bacteria CodeForces - 579A
- CodeForces 579A Raising Bacteria (水)
- Codeforces 579A. Raising Bacteria(位运算)
- Codeforces Round #320 (Div. 2) 579A Raising Bacteria(脑洞)
- Codeforces Round #320 (Div. 2) 579A. Raising Bacteria
- codeforces—— 579A —— Raising Bacteria
- coderforce 579A Raising Bacteria
- Codeforces 320A - Raising Bacteria(思维)
- A. Raising Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- codeforces #320 div2A Raising Bacteria
- Code Forces 579 A. Raising Bacteria(位运算)
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]A Raising Bacteria
- Raising Bacteria
- android.graphics.BitmapRegionDecoder
- 树莓派3之解决串口使用问题
- angular 阻止事件冒泡
- 0001-关于jdk和jre
- FLT_EPSILON定义在<float.h> 趋0最小
- Raising Bacteria CodeForces - 579A
- 《仰天大笑出门去,这个杀手有脾气-雾满拦江》
- 【Dongle】【Java】规范汇总
- 2.系统开发基础-软件维护(6)
- 目标的最后位置
- 支付宝 Android 版使用的开源组件
- 完美字符串 输入一个字符串S(S的长度 <= 10000),S中没有除字母外的其他字符。由你将1-26分配给不同的字母,使得字符串S的完美度最大,输出这个完美度。如dad 77
- 带你一步一步揭开Rxjava2.0的神秘面纱(1)
- eclipse插件下载集合