HDU 5272
来源:互联网 发布:mac怎么打出emoji 编辑:程序博客网 时间:2024/06/03 21:45
Dylans loves numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 848 Accepted Submission(s): 467
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 numberN .
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.
His another ID is s1451900 in BestCoder.
And now today's problems are all about him.
Dylans is given a number
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 nextT lines there is a number N .
0≤N≤1018,T≤1000
In the next
Output
For each test case,output an answer.
Sample Input
15
Sample Output
2
题意:找出一个数的二进制表示中有几个连续的1的数字段。
分析:很简单的题,用1,2,4,8.。。。。。。和给定数字&一下找出给定数字的二进制表达,然后遍历一下就可以了。
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int w[100];long long p(long long x){return 1 << x;}int main(){int t;cin >> t;while (t--){long long n;cin >> n;long long result = 0;int flag = 0;while(n){if (n&1){if (flag == 0)result++;flag = 1;}elseflag = 0;n /= 2;}cout << result << endl;}return 0;}
0 0
- hdu 5272
- HDU 5272
- HDU 5272 解题报告
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- myssql 批量插入数据
- VR应用在直播领域上的实践与探索
- 3140 Contestants Division
- unity2D人物移动撞墙体抖动
- 新手必备——android studio设置大全(更改没有勾选的设置)
- HDU 5272
- 开启多线程退出后终止异步任务
- 一不小心成了傻白甜
- Socket一些函数相关的返回值
- FatFS文件系统详解-附移植建议
- RxAndroid入门详解
- android material design之snackbar
- BCGControlBar中文教程:Ribbon Bar(3/3)
- Unity 2D 开发(1)精灵+精灵编辑_蓝鸥