DHUOJ 2016060702
来源:互联网 发布:国家发改委 大数据 编辑:程序博客网 时间:2024/05/21 10:22
Raising Bacteria
From: DHUOJ, 2016060702
Description
You are a lover of bacteria so you want to raise some bacteria in a box. Initially, the box is empty. Every morning, you can put any number of bacteria into the box. Every night every bacterium in the box will split into two bacteria. You hope to see exactly
Input
There are several test cases. Each case contains only one integer
Output
For each case, output the only line containing one integer: the answer.
Sample Input
58
Sample Output
21
Author: handoku
思路:
每次模2,如果不是偶数,则需要新的一条细菌来充当这个1。然后一直除2,看这个过程中会产生几个1,就需要几条细菌。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<stack>using namespace std; int main() { int x,cnt=0;; while(~scanf("%d",&x)){ cnt=0; while(x>1) { if(x%2==1) { cnt++; } x=x/2; } printf("%d\n",cnt+1); } return 0; }
阅读全文
0 0
- DHUOJ 2016060702
- DHUOJ 2017052401
- DHUOJ 2017052403
- DHUOJ 2016060703
- DHUOJ 2017051002
- 线段树
- java面试基础题之二
- Housewife Wind 【LCA转RMQ 求最短路+边权修改】or 【树链剖分】
- 玩转Spring Boot 集成Dubbo
- leofs Gateway介绍
- DHUOJ 2016060702
- Dubbo在Spring和Spring Boot中的使用
- springMVC同属性名的多对象
- Linux中Hard link和Symbol link的区别
- java 定时任务 Quartz 的认识
- USACO-Section1.3Ski Course Design[其他]
- spring+hbase集成
- java 文件属性的读取
- tomcat的配置