• hdu 5272 Dylans loves numbers


    题目连接

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

    Dylans loves numbers

    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 leq N leq 10^{18},T leq 1000$

    Output

    For each test case,output an answer.

    SampleInput

    1

    5

    SampleOutput

    2

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 #include<set>
     9 using std::cin;
    10 using std::cout;
    11 using std::endl;
    12 using std::find;
    13 using std::sort;
    14 using std::set;
    15 using std::map;
    16 using std::pair;
    17 using std::vector;
    18 #define sz(c) (int)(c).size()
    19 #define all(c) (c).begin(), (c).end()
    20 #define iter(c) __typeof((c).begin())
    21 #define cls(arr,val) memset(arr,val,sizeof(arr))
    22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    23 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    24 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    25 #define pb(e) push_back(e)
    26 #define mp(a, b) make_pair(a, b)
    27 const int Max_N = 100010;
    28 typedef unsigned long long ull;
    29 int main() {
    30 #ifdef LOCAL
    31     freopen("in.txt","r",stdin);
    32     freopen("out.txt","w+",stdout);
    33 #endif
    34     int t;
    35     ull ret;
    36     scanf("%d",&t);
    37     while(t--) {
    38         int f = 1, ans = 0;;
    39         scanf("%lld",&ret);
    40         while(ret) {
    41             if(f) {
    42                 if(ret & 1) ans++, f = 0;
    43             } else if(!(ret & 1)) f = 1;
    44             ret >>= 1;
    45         }
    46         printf("%d
    ",ans);
    47     }
    48     return 0;
    49 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    Makefile:2:*** missing separator. Stop.
    Code笔记之:对使用zend加密后的php文件进行解密
    Apache 访问控制
    leetcode-21-合并两个有序链表
    tcp四次挥手的过程
    实现一个LRU算法
    redis为什么快
    二月春日
    你的支持会鼓励我更积极地创作
    静夜思·静夜祈愿
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4592285.html
Copyright © 2020-2023  润新知