acm-Same binary weight
来源:互联网 发布:火炬之光2for mac汉化 编辑:程序博客网 时间:2024/04/26 06:33
Same binary weight
时间限制:300 ms | 内存限制:65535 KB
难度:3
- 描述
The binary weight of a positive
integer is thenumber of 1's in its binary representation.for example,the decmialnumber 1 has a binary weight of 1,and the decimal number 1717(which is 11010110101 in binary) has a binary weight of 7.Give apositive integer N,return the smallest integer greater than N thathas the same binary weight as N.N will be between 1 and1000000000,inclusive,the result is guaranteed to fit in a signed32-bit interget. - 输入
- The input has multicases and each case contains a integerN.
- 输出
- For each case,output the smallest integer greater than N that hasthe same binary weight as N.
- 样例输入
17174712555555
- 样例输出
171881117555557
- 来源
- topcoder
- 代码:
- #include
#include
#include
#include
using namespace std;
int main()
{
int n;
int i,j,count;
while(scanf("%d",&n)!=EOF)
{
bitset<32> b;
i=0;
while(n)
{
if(n&1)
b.set(i);
i++;
n>>=1;
}
count=0;
for(j=0;j
{
if(b.test(j))
{
count++;
b.reset(j);
if(!b.test(j+1))
{
b.set(j+1);
break;
}
}
}
for(j=0;j
b.set(j);
printf("%d\n",b.to_ulong());
}
return 0;
}
- acm-Same binary weight
- 练习场acm 题目412 Same binary weight
- Same binary weight
- NYOJ - Same binary weight
- Same binary weight 数学
- Same binary weight
- Same binary weight
- Same binary weight
- Same binary weight
- Same binary weight
- Same binary weight
- Same binary weight
- NYOJ 412 Same binary weight
- nyoj 412Same binary weight
- Same binary weight bitset(STL)
- NYOJ 412 Same binary weight
- nyoj 412 Same binary weight
- nyoj-412-Same binary weight(位运算)
- acm-对决
- [Qt教程] 第37篇 网络(七)TCP(一)
- acm-变态最大值
- acm-懒省事的小明
- acm-扩展欧几里得
- acm-Same binary weight
- acm-汉诺塔(三)
- acm-GoroSort
- acm-递推求值
- acm-Matrix Power Series
- acm-Kiki & Little Kiki 2
- scala good code
- acm-星际旅行
- acm-K steps