hdu 5272 Dylans loves numbers
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5272
Dylans loves numbers
Description
Who is Dylans?You can find his ID in UOJ and Codeforces.
His another ID is s1451900 in BestCoder.
And now today's problems are all about him.
Dylans is given a number $N.$
He wants to find out how many groups of "1" in its Binary representation.
If there are some "0"(at least one)that are between two "1",
then we call these two "1" are not in a group,otherwise they are in a group.
Input
In the first line there is a number $T.$
$T$ is the test number.
In the next $T$ lines there is a number $N.$
$0 \leq N \leq 10^{18},T \leq 1000$
Output
For each test case,output an answer.
SampleInput
1
5
SampleOutput
2
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
const int Max_N = ;
typedef unsigned long long ull;
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w+",stdout);
#endif
int t;
ull ret;
scanf("%d",&t);
while(t--) {
int f = , ans = ;;
scanf("%lld",&ret);
while(ret) {
if(f) {
if(ret & ) ans++, f = ;
} else if(!(ret & )) f = ;
ret >>= ;
}
printf("%d\n",ans);
}
return ;
}
hdu 5272 Dylans loves numbers的更多相关文章
- hdu 5272 Dylans loves numbers 水题
Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- HDU 5273 Dylans loves numbers(水题)
题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...
- hdu 5274 Dylans loves tree(LCA + 线段树)
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- Hdu 5274 Dylans loves tree (树链剖分模板)
Hdu 5274 Dylans loves tree (树链剖分模板) 题目传送门 #include <queue> #include <cmath> #include < ...
- hdu 5273 Dylans loves sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...
- hdu 5274 Dylans loves tree
Dylans loves tree http://acm.hdu.edu.cn/showproblem.php?pid=5274 Time Limit: 2000/1000 MS (Java/Othe ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- hdu 5274 Dylans loves tree (树链剖分 + 线段树 异或)
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 5273 Dylans loves sequence 暴力递推
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...
随机推荐
- 慕课网-安卓工程师初养成-2-10 Java中的强制类型转换
来源:http://www.imooc.com/code/1241 相信小伙伴们也发现了,尽管自动类型转换是很方便的,但并不能满足所有的编程需要. 例如,当程序中需要将 double 型变量的值赋给一 ...
- 洛谷P1470 最长前缀 Longest Prefix
P1470 最长前缀 Longest Prefix 73通过 236提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 求大神指导,为何错? 题目描述 在生 ...
- PNG图片数据解析
PNG是一种非常流行的图片格式,它不仅支持透明效果,而且图片数据经过了压缩处理,所以广泛用于web等应用. PNG的文件格式: PNG文件中的数据,总是以一个固定的8个字节开头: (图片来自http: ...
- Android基础总结(7)——异步消息处理
服务(Service)是Android中实现程序后台运行的解决方案,它非常适合用于去执行哪些不需要和用户交互而且还要长期运行的任务.服务的运行不依赖任何用户界面,即使当程序被切换到后台,或者用户打开了 ...
- dedecms代码研究一
dedecms相信大家一定都知道这个cms系统,功能比较强大,有比较完善的内容发布,还有内容静态化系统,还有就是它有自己独特的标签系统和模板系统.而模板系统也是其他cms系统比较难模仿的的东西,这个东 ...
- 用C#访问Dynamic AX的WebService.
第 1 步:创建 C# WinForm 应用程序 针对本演练,您将创建访问报表服务器 Web 服务的简单控制台应用程序.本演练假定您是在 Visual Studio 环境中进行开发的.测试范例基于VS ...
- C# 共用的返回数据类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Dscf ...
- 第1部分: 游戏引擎介绍, 渲染和构造3D世界
原文作者:Jake Simpson译者: 向海Email:GameWorldChina@myway.com ---------------------------------------------- ...
- .NET常用类库知识总结
常用类库之.NET中的字符串 字符串的特性 1.不可变性 由于字符串是不可变的的,每次修改字符串,都是创建了一个单独字符串副本(拷贝了一个字符串副本).之所以发生改变只是因为指向了一块新 ...
- Windows下WEB服务器的选择与搭建
本文主要基于支持perl的web服务器的选择. 一直基于web开发,服务器都是linux下使用webmin搭建的,惭愧的说一句,这么多年,也好好研究过WEB服务器,单从这个角度,是不是可以反应出web ...