CF579 - A Raisinng bacteria
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 x bacteria 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
- 5
- 2
- 8
- 1
Note
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
题解:水题;
参考代码:
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<cstdlib>
- #include<algorithm>
- #include<queue>
- #include<deque>
- #include<stack>
- #include<set>
- #include<vector>
- #include<map>
- using namespace std;
- typedef long long LL;
- typedef pair<int,int> PII;
- #define PI acos(-1)
- #define EPS 1e-8
- const int INF=0x3f3f3f3f;
- const LL inf=0x3f3f3f3f3f3f3f3fLL;
- const int maxn=1e5+;
- int main()
- {
- int n;
- while(~scanf("%d",&n))
- {
- int cnt=;
- for(int t=;t<=n;t*=)
- {
- if((t&n)!=) cnt++,n-=t;
- }
- printf("%d\n",cnt);
- }
- return ;
- }
CF579 - A Raisinng bacteria的更多相关文章
- Codeforces__Raising Bacteria
题目传送门:Raising Bacteria //问题描述:一个盒子里面放一个细菌在一天可以增生两个细菌. 现在已知盒子里面细菌的个数,问你最初放多少个细菌可以增生盒子里面的细菌数量 //输入:盒子中 ...
- Codeforces 579A. Raising Bacteria
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. ...
- Gym - 101911C Bacteria (规律题)
传送门:点我 Time limit2000 ms Memory limit262144 kB Recently Monocarp has created his own mini-laboratory ...
- LightOJ 1220 Mysterious Bacteria(唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1220 Mysterious Bacteria Time Limit:500MS Memo ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Bacteria (Gym - 101911C)
2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage Bacteria Gym - 101911C ...
- LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria
题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...
- LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1220 题意:已知 x=bp 中的 x 求最大的 p,其中 x b p 都为整数 x = ...
- Codeforces400D Dima and Bacteria
题意:给你一个无向有权的图,图上的点被分成了几类,对于同类的点你需要判断它们之间相互的最短距离是不是0.满足这个条件之后要输出的是类与类之间的最短距离的矩阵.点给到10^5这么多,判断同类的点显然不能 ...
随机推荐
- 使用Bootstrap制作简单的旅游主页
页面效果 代码: 需要导入bootstrapt文件,解压至项目中. 下载地址:https://v3.bootcss.com/getting-started/#download <!DOCTYPE ...
- 学习Java第一步:安装Intellij IDEA和JDK
注:其实真正学习一门新语言的第一步并不是安装开发工具,我是C#转JAVA,有一点编程经验了,所以可以直接跳过前面几步,直接上IDE. 1.下载IntelliJ IDEA [官网] http://www ...
- django学习与实践
Django简介 Django是一个由Python写成的开放源代码的Web应用框架,它最初是被用来开发管理劳伦斯出版集团旗下的一些以新闻内容为主的网站,即CMS(内容管理系统)软件. 并于2005 ...
- 我的第一个 60 k+ Star Java开源项目
JavaGuide([Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识):https://github.com/Snailclimb/JavaGuide. 人生总有各种各样的 ...
- 从0开始学前端(笔记备份)----HTML部分 Day2 HTML表格表单
- 领扣(LeetCode)回文链表 个人题解
请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶:你能否用 O(n) 时间复杂 ...
- ZeroC ICE的远程调用框架 class与interface
我们在ice文件中定义的class或interface,slice都会为我们生成stub存根类和skeleton骨架类.在这里要注意slice并没有分别生成两份单独用在客户端或服务端的接口给开发分发. ...
- 标准库bufio个人详解
本文是我有通俗的语言写的如果有误请指出. 先看bufio官方文档 https://studygolang.com/pkgdoc文档地址 主要分三部分Reader.Writer.Scanner 分别是读 ...
- scss--函数 (Functions)--unitless
(Sass::Script::Value::Bool) unitless($number) Returns whether a number has units. Examples: unitless ...
- Python--将文件夹中图片按照横屏竖屏进行分类
搬运链接:https://www.jianshu.com/p/c8be54282e77 """ 可以遍历输入的路径的指定后缀的文件,主要是用来筛选图片,将图片分成 横屏, ...