HDU 5272 Dylans loves numbers

Dylans loves numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 58    Accepted Submission(s): 49

Problem 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≤N≤1018,T≤1000

Output

For each test case,output an answer.

Sample Input

1
5

Sample Output

2

Source

BestCoder Round #45

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
const int N = 5005;
#define LL __int64

int main()
{
   LL n;
   int a[100],T;
   scanf("%d",&T);
   while(T--)
   {
       scanf("%I64d",&n);
       int k=0,flag=0;
       while(n){
            if(n&1){
                if(flag==0)k++; flag=1;
            }
            else flag=0;
            n/=2;
       }
       printf("%d\n",k);
   }
    return 0;
}

时间: 2024-10-25 19:20:43

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.php?pid=5272 Description Dylans是谁?你可以在 UOJ 和 Codeforces上看到他.在BestCoder里,他有另外一个ID:s1451900.今天的题目都和他有关哦.Dylans得到了一个数N.他想知道N的二进制中有几组1.如果两个1之间有若干个(至少一个)0

HDU 5273 Dylans loves numbers(水题)

题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到1时,flag=0就统计,当flag=1时就不统计. 1 #include <bits/stdc++.h> 2 #define LL long long 3 using namespace std; 4 5 int main() 6 { 7 int t; 8 LL n; 9 cin>>

(bc #45) A - Dylans loves numbers (hdu 5272)

Dylans loves numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 569    Accepted Submission(s): 320 Problem Description Who is Dylans?You can find his ID in UOJ and Codeforces.His another

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

Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Description Dylans得到了N个数a[1]...a[N].有Q个问题,每个问题形如(L,R)他需要求出L−R这些数中的逆序对个数.更加正式地,他需要求出二元组(x,y)的个数,使得L≤x,y≤R且x<y且a[x]>a[y] Input 第一行有两个数N和Q

HDU 5273 Dylans loves sequence(区间DP)

Dylans loves sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 114    Accepted Submission(s): 59 Problem Description Dylans is given N numbers a[1]....a[N] And there are Q questions. E

HDU 5274 Dylans loves tree(LCA+dfs时间戳+成段更新 OR 树链剖分+单点更新)

Problem Description Dylans is given a tree with N nodes. All nodes have a value A[i].Nodes on tree is numbered by 1∼N. Then he is given Q questions like that: ①0 x y:change node x′s value to y ②1 x y:For all the value in the path from x to y,do they

Dylans loves numbers

Problem 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

hdu 5273 Dylans loves sequence

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5273 bestcoder round#45 1002 题目大意: 给出一个有n个数的任意序列,问[r,l]区间内一共有多少对倒置数? 解题思路: 由于1<=n<=1000,所以想怎么做怎么做,当时不知道怎么了,思路不错,但是就是代码wa. 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h&

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

题意:给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: 先分析: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆成两部分,那么[L,k]中的逆序对要算上, (k,R]中的逆序对也要算上,还有一些逆序对假设为(l,r),l在左部分,r在右部分.则应该是3部分来构成,设3部分为A,B,C,那么ans=A+B+C . 而如果将k移到最右边,比如k=R-1,那么区间拆成[L,k]和(K,R],而(K,R]其实就只有R一