zoukankan      html  css  js  c++  java
  • HDU-5272

    Dylans loves numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 201    Accepted Submission(s): 136


    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
    bestcoder round#45 1001
    /**
              题意:给出一个数,然后求该数的二进制的有多少组1 
                        比如10101     1101101   都是三组 
              做法:暴力 还有如果计算一个数的二进制有多少1
              可以
              while(n)
              {
                        count++;
                        n = n&(n-1);
              }
    **/
    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    int main()
    {
    //#ifndef ONLINE_JUDGE
    //          freopen("in.txt","r",stdin);
    //#endif // ONLINE_JUDGE
              int T;
              scanf("%d",&T);
              while(T--)
              {
                        long long n;
                        long long sum = 0;
                        int tt = 0;
                        scanf("%lld",&n);
                        int cnt = 0;
                        while(n)
                        {
                                  cnt = n % 2;
                                  if(tt == 0 && cnt == 1) sum++;
                                  n /= 2;
                                  tt = cnt;
                        }
                        printf("%lld
    ",sum);
              }
              return 0;
    }
  • 相关阅读:
    URAL 1658. Sum of Digits(DP)
    HDU 4433 locker(SPFA+DP)
    Vijos 1092 全排列
    POJ 1141 Brackets Sequence(DP)
    HDU 4597 Play Game
    HDU 1693 Eat the Trees(插头DP)
    USACO 5.4 Twofive(DP)
    USACO 5.5 Hidden Password(搜索+优化)
    USACO 5.5 Picture(周长并)
    USACO 5.4 Telecowmunication(最大流+枚举)
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4592465.html
Copyright © 2011-2022 走看看