(BC #45) A-dylans loves numbers (Hdu 5272)

Source: Internet
Author: User

Dylans loves numbers

Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 569 Accepted Submission (s): 320


Problem descriptionwho 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 numberN.
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.

Inputin The first line there is a numberT.

Tis the test number.

In the nextTLines there is a numberN.

0≤N≤ten,T≤

Outputfor each test case,output an answer.

Sample Input15

Sample Output2

Sourcebestcoder Round #45 is about to explode. Tle became a dog because it was tle, looked at himself did not write Cin cout, estimation is the problem of the algorithm ... I saved every bit of binary into the array, and then I swept it all over ... Well, it's all tle ... That I do not save, directly record the current bits and before bits. Logn's complexity is always OK, huh? also tle .... Well, actually already found that n is less than or equal to 1e18, did not open long long but a long long will be WA ... No reason ... After the real end, changed the next, unexpectedly past ... And then I figured it out. Because there is a while not open long long when the binary system, do not know what to read into, while on the out, so the tle. T T is too young.
/************************************************************************* > File name:code/bc/#45/1001.cpp & Gt AUTHOR:111QQZ > Email: [email protected] > Created time:2015 July 29 Wednesday 13:25 01 seconds ************************* ***********************************************/#include<iostream>#include<iomanip>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#defineY0 ABC111QQZ#defineY1 HUST111QQZ#defineYn hez111qqz#defineJ1 CUTE111QQZ#defineTM CRAZY111QQZ#defineLR DYING111QQZusing namespacestd;#defineREP (i, n) for (int i=0;i<int (n); ++i)typedefLong Longll;typedef unsignedLong LongULL;Const intINF =0x7fffffff;Const intn=1e3+5;intA[n]; LL N,nn;intMain () {intT; CIN>>T;  while(t--) {scanf ("%lld",&N); NN=N; intK =0;  while(NN) {k++; A[K]=nn&1; NN= NN >>1; }    intAns =0;//for (int i = 1; I <= K; i++)//cout<<a[i]<<endl;     for(inti =1; I <= K; i++ )    {        if(a[i]==1&&a[i-1]==0) ans++; } printf ("%d\n", ans); }    return 0;}

(BC #45) A-dylans loves numbers (Hdu 5272)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.