题目连接

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的更多相关文章

  1. hdu 5272 Dylans loves numbers 水题

    Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...

  2. HDU 5273 Dylans loves numbers(水题)

    题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...

  3. hdu 5274 Dylans loves tree(LCA + 线段树)

    Dylans loves tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  4. Hdu 5274 Dylans loves tree (树链剖分模板)

    Hdu 5274 Dylans loves tree (树链剖分模板) 题目传送门 #include <queue> #include <cmath> #include < ...

  5. hdu 5273 Dylans loves sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...

  6. hdu 5274 Dylans loves tree

    Dylans loves tree http://acm.hdu.edu.cn/showproblem.php?pid=5274 Time Limit: 2000/1000 MS (Java/Othe ...

  7. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  8. hdu 5274 Dylans loves tree (树链剖分 + 线段树 异或)

    Dylans loves tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  9. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

随机推荐

  1. yii中第三方库

    yii中存在一些路径别名:ext:表示包含了所有第三方扩展的目录  参考:http://www.yiiframework.com/doc/guide/1.1/zh_cn/basics.namespac ...

  2. ASP.NET MVC4 学习系统四(视图)

    视图(Views)    在ASP.NET MVC框架中,想要返回给用户HTML的控制器操作,就要返回ActionResult类型的ViewResult实例,ActionResult知道如何渲染应答结 ...

  3. MVC ckeditor的基本使用

    之前在自己的WebForm练习项目里面用到过ckeditor,时隔蛮久后,今天再一次把ckeditor运用到MVC里面,用于最近着手开发的企业站的新闻动态的内容之新增与修改. 找到的资料都说要把下载的 ...

  4. namespace的用法

    C++中采用的是单一的全局变量命名空间.在这单一的空间中,如果有两个变量或函数的名字完全相同,就会出现冲突.当然,你也可以使用不同的名字,但有时我们并不知道另一个变量也使用完全相同的名字:有时为了程序 ...

  5. C# 反射操作方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  6. 二级路由器设置为何要关闭DHCP服务

    因为如果不关闭dhcp的话会和一级路由相冲突,你这个因该是lan口的连接法吧,如果不然的话是不需要关闭dhcp功能的路由器和路由器的连接方法有两种,一种是wan口连,一种是lan口连方法1:WAN口连 ...

  7. 十四、Struts2的国际化

    十四.Struts2的国际化 1.配置全局国际化消息资源包 配置全局消息资源包 <!--配置全局消息资源包 -->     <constant name="struts.c ...

  8. (图 BFS)走迷宫

    题目: 给一个迷宫,求出从起点到终点的路径.迷宫 src.txt 文件内容如下,第一行是迷宫的行列数,后面行是迷宫,1表示可行走,0表示不可以通过,起点是最左上角,终点是最右下角: 解析: 其实就是图 ...

  9. PL/SQL Developer中文注释乱码的解决办法

    1.检查服务器编码: 执行SQL语法: select * from v$nls_parameters; 2.设置本地客户端编码: 进入 我的电脑,属性,高级,环境变量,添加2项:LANG=zh_CN. ...

  10. set 赋值(转载)

    名著<C#设计模式>第9章“观察者模式”涉及了标准的事件处理流程,作者在探讨属性值变更时给出一个如下示例代码(P73-74): pulbic abstract class TpeakFun ...