Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=5272
Dylans loves Numbersdescription
Who is Dylans? You can find its ID in Uoj and Codeforces.
His another ID is s1451900 in Bestcoder.
And now today ' s problems is all about him.
Dylans is given a number $N. $
He wants to the find out how many groups of "1" in its Binary representation.
If there is some "0" (at least one) that is between the "1",
Then we call these the "1" is not in a group,otherwise they is in a group.
Input
The first line there is a number $T. $
$T $ is the test number.
The next $T $ lines There is a number $N. $
$ \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 usingstd::cin;Ten usingstd::cout; One usingStd::endl; A usingStd::find; - usingStd::sort; - usingSTD::Set; the usingStd::map; - usingstd::p air; - usingstd::vector; - #defineSZ (c) (int) (c). Size () + #defineAll (c) (c). Begin (), (c). End () - #defineITER (c) __typeof ((c). Begin ()) + #defineCLS (arr,val) memset (arr,val,sizeof (arr)) A #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) at #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - #definePB (E) push_back (e) - #defineMP (A, b) Make_pair (A, B) - Const intMax_n =100010; -typedef unsignedLong Longull; in intMain () { - #ifdef LOCAL toFreopen ("In.txt","R", stdin); +Freopen ("OUT.txt","w+", stdout); - #endif the intT; * ull ret; $scanf"%d",&t);Panax Notoginseng while(t--) { - intf =1, ans =0;; thescanf"%lld",&ret); + while(ret) { A if(f) { the if(Ret &1) ans++, F =0; +}Else if(! (Ret &1)) F =1; -RET >>=1; $ } $printf"%d\n", ans); - } - return 0; the}
View Code
HDU 5272 Dylans loves numbers