CF 579A Raising Bacteria
2015-09-17 10:20
435 查看
题意:细菌爱好者在盒子里面培养细菌。最初盒子是空的,每天可以往盒子里面添加任意数目的细菌,而且每天每个细菌会分裂成两个。在某一时刻要想获得某一数量的细菌,要求最初放置的最少的细菌数目。
思路: 求出 n 的二进制形式中 1 的个数即可。
代码:
思路: 求出 n 的二进制形式中 1 的个数即可。
代码:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<queue> #include<algorithm> #include<cmath> #include<map> using namespace std; #define INF 0x7fffffff int main(){ int i,n; while(scanf("%d",&n) == 1){ int cnt = 0; int t = 1; for( ; t <= n ; t *= 2){ if( (t & n) != 0){ cnt++; n -= t; } } printf("%d\n",cnt); } return 0; }
相关文章推荐
- leetcode:Contains Duplicate III
- AIX .tgz的安装包及登录日志查看
- Email正则表达式日常整理大全
- 使用Jmai发送邮件
- Container With Most Water 解答
- [CareerCup] 9.1 Climbing Staircase 爬楼梯
- cf#320 Div.2 Problem A Raising Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- rails s的时代一去不复返了
- Email正则表达式日常整理大全
- exchange email account最多只能在10个终端上设置
- ZOJ.2060 Fibonacci Again【数论-斐波那契】 2015/09/16
- [BetterExplained]为什么你应该(从现在开始就)写博客
- 使用dir()、readdir()和glob()遍历目录及测试性能 http://blog.csdn.net/hpy1165331898/article/details/44918879
- RAID详解[RAID0/RAID1/RAID5/RAID10]
- mdadm使用详解及RAID 5简单分析
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATI
- Debain下源码安装OpenVAS
- 使用slidingmeu_actionbarsherlock_lib的问题和The hierarchy of the type MainActivity is inconsistent
- Async/Await - Best Practices in Asynchronous Programming