码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5272 Dylans loves numbers

时间:2015-06-21 20:59:05      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

题目连接

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\n",ans);
47     }
48     return 0;
49 }
View Code

 

hdu 5272 Dylans loves numbers

标签:

原文地址:http://www.cnblogs.com/GadyPu/p/4592285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!