题目连接

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. 默菲定律 [Murphy's Law]

    一.关于默菲定律(Murphy's Law)   “墨菲定律”.“帕金森定律”和“彼德原理”并称为二十世纪西方文化三大发现. “墨菲定律”的原话是这样说的:If there are two or mo ...

  2. 启动obiee

    启动obiee:1.启动数据库第一步:打开Oracle监听$ lsnrctl start第二步:使用sysdab角色登录sqlplussqlplus / as sysdba第三步:启动数据库SQL&g ...

  3. 学习练习 Java冒泡排序 二分查找法

    冒泡排序: // 冒泡排序 /* System.out.println("请输入要排序的个数:"); Scanner v = new Scanner(System.in); int ...

  4. 【MySQL】MySQL索引背后的之使用策略及优化【转】

    转自:http://database.ctocio.com.cn/353/11664853.shtml 另外很不错的对于索引及索引优化的文章: http://www.cnblogs.com/magia ...

  5. ASP.NET的SEO--- Global.asax和HttpModule中的RewritePath()方法

    本系列目录 因为在网上搜到了很多这方面的文章,而且UrlRewrite中SEO中的重要性也在逐步下降,所以这一节我就写得简单一些.以下是几个重点: 1.UrlRewrite,顾名思义,只是针对URL进 ...

  6. iOS取证将如漫漫长夜

    日前因恐攻一案,FBI对一支已上锁的iPhone 5c束手无策,美国法院出具命令要求苹果配合,但被苹果公司执行长库克以维护安全及隐私为由悍然拒绝. 平心而论,各有其立场,但在一个犯罪案件之中,真的可以 ...

  7. JAVA设计模式--strategy(策略者模式)

    概念策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化.(原文:The Strategy Pattern defines a fa ...

  8. 在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境

    阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在 ...

  9. phalcon框架学习之router

    router定义 在DI中注册router的方法: $di->set('router', function(){ $router = new Phalcon\Mvc\Router(); $rou ...

  10. 飞翔的圆(Flappy Bird)游戏源码

    这个源码是一个不错的休闲类的游戏源码,飞翔的圆(Flappy Bird)游戏源码V1.0,本项目是一个仿Flappy Bird的小游戏,只不过是把Flappy Bird里面的鸟替换成了简单的圆.感兴趣 ...