zoukankan      html  css  js  c++  java
  • 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 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.
    0N1018,T1000
     
    Output
    For each test case,output an answer.
     
    Sample Input
    1 5
     
    Sample Output
    2
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 int main()
     8 {
     9     __int64 n;int i,j,k,ans,flag,t;
    10     while(scanf("%d",&t)!=EOF)
    11     {
    12         while(t--)
    13         {
    14             scanf("%I64d",&n);
    15             ans=0;flag=1;
    16             while(n)
    17             {
    18                 k=n%2;n/=2;
    19                 if(k==1)
    20                 {
    21                     if(flag==1)
    22                     ans++;
    23                     flag=0;
    24                 }
    25                 else
    26                 {
    27                     flag=1;
    28                 }
    29             }
    30             cout<<ans<<endl;
    31         }
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    常用的adb命令
    Jmeter之计数器
    Jmeter跨线程组传递变量
    Jmeter的属性和变量
    Jmeter之关联——常用提取器
    Jmeter常用的逻辑控制器
    HDU 1262 寻找素数对 模拟题
    HDU 1431 素数回文 离线打表
    HDU 2553 N皇后问题
    HDU 2093 考试排名 模拟题
  • 原文地址:https://www.cnblogs.com/WHLdbk/p/5686559.html
Copyright © 2011-2022 走看看