题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处。

思路:一个个数,当遇到第一个1时就将flag置为1;当遇到0就将flag置为0。当遇到1时,flag=0就统计,当flag=1时就不统计。

 #include <bits/stdc++.h>
#define LL long long
using namespace std; int main()
{
int t;
LL n;
cin>>t;
while(t--)
{
cin>>n;
int cnt=,flag=;
while(n)
{
if((n&)==)
{
if(!flag)
{
flag=;
cnt++;
}
}
else
flag=;
n>>=;
}
printf("%d\n",cnt);
}
return ;
}

AC代码

HDU 5273 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 sequence

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

  3. hdu 5272 Dylans loves numbers

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...

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

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

  5. HDU 5273 Dylans loves sequence 暴力递推

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

  6. hdu 5268 ZYB loves Score 水题

    ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  7. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  8. HDU 5655 CA Loves Stick 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 CA Loves Stick Accepts: 381   Submissions: 3204 ...

  9. HDU 5273 Dylans loves sequence (逆序对,暴力)

    题意: 给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆 ...

随机推荐

  1. iOS网络检测

    使用之前请从Apple网站下载示例:点此下载 Reachability 中定义了3种网络状态: typedef enum : NSInteger { NotReachable = ,//无网络 Rea ...

  2. Ms sql server sql优化技巧

    SET STATISTICS PROFILE ON SET STATISTICS IO ON SET STATISTICS TIME ON SELECT * FROM userinfo WHERE N ...

  3. 为什么toString方法可以用来区分数组和对象?

    首先大家都应该知道在javascript中只有是对象都存在toString方法,将调用该方法的值转换为字符串返回,如下: var arr = [1, 2, 3]; console.log(arr.to ...

  4. C# winform post请求数据

    刚到公司混的时候,老板要求实现一个从C#的windows应用程序传参数到一个网页,然后这个网页不显示出来,但能把数据返回给应用程序的功能,问了好多人,找了好多资料,都搞不定,后来还是在老板的帮助下搞定 ...

  5. Spring中RedirectAttributes对象重定向传参

    Spring3中的FlashAttribute 为 了防止用户刷新重复提交,save操作之后一般会redirect到另一个页面,同时带点操作成功的提示信息.因为是Redirect,Request里 的 ...

  6. a cold welcome

    What does 'a cold welcome' refer to? On wednesday evening,we went to the town hall. It was the last ...

  7. 网络处理1-异步GET请求

    前言 云计算 近几年来,云计算是一个非常热门的技术名词,很多专家认为,云计算会改变互联网的技术基础,甚至会影响整个产业的格局.可能还很多人不了解什么是云计算,简单来说,就是把用户的数据(比如文档.照片 ...

  8. React可控组件与不可控组件

    一.不可控组件 1.简介 2.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta ch ...

  9. MongoDB使用SSL

    1. MongoDB对SSL的支持情况 MongoDB社区版本不支持SSL,企业版提供对SSL的支持.MongoDB源代码中包含SSL的实现,可以自己编译带SSL的MongoDB. MongoDB支持 ...

  10. mysql union和union all

    UNION 操作符用于合并两个或多个 SELECT 语句的结果集.UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型. union 是对数据进行并集操作,不包括重复 ...