hdu 5272 Dylans loves numbers 水题

时间:2021-12-06 03:59:02

Dylans loves numbers

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5272

Description

Dylans是谁?你可以在 UOJ 和 Codeforces上看到他。
在BestCoder里,他有另外一个ID:s1451900。
今天的题目都和他有关哦。
Dylans得到了一个数N。他想知道N的二进制中有几组1。
如果两个1之间有若干个(至少一个)0 “挡住”,他们就不是同一组的,
否则他们就是同一组的。

Input

第一行读入一个数T表示数据组数。
接下来T行,每行一个数N。
0≤N≤1018,T≤1000

Output

对于每组数据,输出一个数表示答案。

Sample Input

1
5

Sample Output

2

HINT

题意

题解:

这道题就是按照题意模拟。
设读入的数是N,我们先把N分解成二进制形式放在数组A里。(正反顺序没有关系)
然后对A数组循环一边,如果当前位置是1而前一位是0那么计数器就++。注意一些小的细节。
时间复杂度为O(T∗log(N))

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-5
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int main()
{
int t=read();
while(t--){
ll n=read();
int ans=;
int flag=;
while(n)
{
if(flag)
{
if(n&)
{
ans++;
flag=;
}
}
else if(!(n&))
{
flag=;
}
n>>=;
}
cout<<ans<<endl;
}
}

hdu 5272 Dylans loves numbers 水题的更多相关文章

  1. hdu 5272 Dylans loves numbers

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

  2. HDU 5273 Dylans loves numbers(水题)

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

  3. hdu 5268 ZYB loves Score 水题

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

  4. HDU 5645 DZY Loves Balls 水题

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

  5. HDU 5655 CA Loves Stick 水题

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

  6. hdu 5274 Dylans loves tree&lpar;LCA &plus; 线段树&rpar;

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

  7. Hdu 5274 Dylans loves tree &lpar;树链剖分模板&rpar;

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

  8. hdu 5273 Dylans loves sequence

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

  9. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

随机推荐

  1. js判断本地是否安装app

    var ua = navigator.userAgent.toLowerCase(); 1.判断是否是微信 function isWeixinBrowser() { return (/micromes ...

  2. ASP&period;NET前端解决方案之一:Ext&period;Net入门随笔1

    最近因为公司需要,进一步研发了Ext.Net技术,这里先做一个简明的介绍,给自己和大家记录一个初步的概念. 什么是Ext Ext就是ExtJS,引用下百度的解释:“ExtJS是一种主要用于创建前端用户 ...

  3. python用装饰器实现缓存函数执行结果

    根据调用的函数名和调用的参数,对函数的结果进行缓存,下次执行的时候就不用重复计算   可以用装饰器来实现   import time import hashlib import pickle cach ...

  4. 有关android UI 线程

    1. GUI线程框架 常见的 Swing, SWT框架都是作为单线程子系统来实现的,实际上不仅限于在Java中, Qt.MacOS Cocoa以及其他的环境中的GUI框架都是单线程的.虽然很多人尝试过 ...

  5. SilkTest天龙八部系列3-动态父窗口

    SilkTest中用parent语句来声明某个window的父窗口,这会帮助silktest在识别该对象时检查其是否是由该父窗口打开,如果parent语句申明的父窗口并不存在,那么该对象无法被正确识别 ...

  6. 英文版Ubuntu安装配置搜狗拼音输入法

    下载搜狗输入法 1 进入搜狗输入法官网,进入上面导航兰的 "输入法Linux版"   2 根据你安装的ubuntu是32位还是64位下载 END ubuntu安装搜狗输入法 1 进 ...

  7. 获取Oracle过程中的OUT SYS&lowbar;REFCURSOR值

    一个项目中的实例:获取Oracle过程中的返回SYS_REFCURSOR.注意:如果SYS_REFCURSOR为一个表或视图.可以通过表名%ROWTYPE获取每行数据,而不必另外定义type. 原过程 ...

  8. Android 视频 教程 源码 电子书 网址

    资源名称 资源地址 下载量 好评率8天快速掌握Android视频教程67集(附源码)http://down.51cto.com/zt/2197 32157Android开发入门之实战技巧和源码 htt ...

  9. 多线程IO通过并发IO来优化性能

    1.通过多线程IO,并发的IO形式来减少顺序IO达到提升性能的目的. 2.具体线程使用方式可以参见  http://www.cnblogs.com/freedommovie/p/7155260.htm ...

  10. node&period;js开发web

    1.安装express框架 使用npm install -g express安装express后,在命令行中执行express,提示没有此命令 原因是在新版的express中命令行需要单独安装 npm ...