Codeforces 579A. Raising Bacteria(位运算)
2016-04-22 17:58
483 查看
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 xbacteria
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
output
input
output
1
solution:
找一下n的二进制中1的个数
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 xbacteria
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
solution:
找一下n的二进制中1的个数
#include<cstdio> using namespace std; int main() { int n,ans=0; scanf("%d", &n); while (n) { if (n & 1)ans++; n >>= 1; } printf("%d\n", ans); return 0; }
相关文章推荐
- 219. Contains Duplicate II
- (总结)密码破解之王:Ophcrack彩虹表(Rainbow Tables)原理详解(附:120G彩虹表下载)
- tomcat-转载来自http://blog.csdn.net/rentian1/article/details/51208703
- vi、ls、cd、pwd、mkdir、rm、mv、cp、cat、tail
- 217. Contains Duplicate
- was compiled with optimization - stepping may behave oddly; variables may not be available.
- 因为类中写静态成员而得到的一点感悟
- Installation Failed. Error chunking
- 人机大战一直有,玩游戏就是最近体验
- 百度启用新顶级域名baidu.news
- Send Report from Same Email Address
- http://blog.csdn.net/a942980741/article/details/39990699
- could not find ParserDetails.ini
- HEVC的Availability计算过程
- HDU 1021 Fibonacci Again
- vSphere-01 Joining your ESXi host to a Windows Domain
- HoloLens开发手记-硬件细节 Hardware Detail
- 人工智能60年:全球人工智能技术大会今日召开,谁在外面“流口水“(即”流哈喇子“)?
- POJ 1995 Raising Modulo Numbers(快速幂取模)
- Rain