首页 > 其他 > 详细

HDU 5272 Dylans loves numbers

时间:2015-06-21 02:06:32      阅读:242      评论:0      收藏:0      [点我收藏+]

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技术分享.

0N10技术分享18技术分享,T1000技术分享
 

Output
For each test case,output an answer.
 

Sample Input
1 5
 

Sample Output
2
 

Source
 
#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;
}


HDU 5272 Dylans loves numbers

原文:http://blog.csdn.net/u010372095/article/details/46575783

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!