As we known, data stored in the computers is in binary form.(数据以二进制形式存储于电脑之中。)The problem we discuss now is about the positive integers and its binary form.

Given a positive integer I, you task is to find out an integer J, which is the minimum integer greater than I, and the number of '1's in whose binary form is the same as that in the binary form of I.

For example, if "78" is given, we can write out its binary form, "1001110". This binary form has 4 '1's. The minimum integer, which is greater than "1001110" and also contains 4 '1's, is "1010011", i.e. "83", so you should output "83".

#include<iostream>
using namespace std; int count(int n)
{
int res=0;
while(n)
{
res++;
n=n&(n-1);
}
return res;
} int main()
{
int n;
while(cin>>n && n)
{
int cnt=count(n);
while(n++)//自增
{
if(cnt==count(n))
{
cout<<n<<endl;
break;
}
}
}
return 0;
}

  

An easy problem(位运算)的更多相关文章

  1. [POJ] 2453 An Easy Problem [位运算]

    An Easy Problem   Description As we known, data stored in the computers is in binary form. The probl ...

  2. An easy problem (位运算)

    [题目描述] 给出一个整数,输出比其大的第一个数,要求输出的数二进制表示和原数二进制表示下1的个数相同. [题目链接] http://noi.openjudge.cn/ch0406/1455/ [算法 ...

  3. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  4. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  5. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  6. 一本通 1223:An Easy Problem

    \[传送门qwq\] [题目描述] 给定一个正整数N,求最小的.比N大的正整数M,使得M与N的二进制表示中有相同数目的1. 举个例子,假如给定的N为78,其二进制表示为1001110,包含4个1,那么 ...

  7. Gym 100818I Olympic Parade(位运算)

    Olympic Parade http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/I [题意]: 给出N个数,找出 ...

  8. acm位运算应用 搜索

    acm位运算应用 搜索 搜索    此处不讲题目,只讲位运算是怎样在这些题中实现和应用的.由于搜索题往往是基于对状态的操作,位运算往往特别有效,优化之后的效果可以有目共睹.    例1.POJ 132 ...

  9. POJ 2531 Network Saboteur 位运算子集枚举

    题目: http://poj.org/problem?id=2531 这个题虽然是个最大割问题,但是分到dfs里了,因为节点数较少.. 我试着位运算枚举了一下,开始超时了,剪了下枝,1079MS过了. ...

随机推荐

  1. windows下XAMPP集成环境中,MySQL数据库的使用

    https://jingyan.baidu.com/article/d169e186467a44436611d8b1.html

  2. linux下定时网站文件备份和数据备份以及删除旧备份标准代码

    直切正题: 文件备份:web.sh 数据备份:db.sh 删除旧备份:clear.sh vi web.sh文件内容为: #!/bin/bash        解释:shell脚本标准头 cd  网站文 ...

  3. 安装 browsercookie 模块详细步骤

    在安装browsercookie时遇到了不少问题,现在终于解决了,把方法分享下,希望能帮大家节约点时间 到此网址上下载压缩包: https://pypi.org/project/browsercook ...

  4. 小白的java学习之路 “ 选择结构(一)”

    if选择结构: if选择结构是根据条件判断之后再做处理的一种语法结构. 1.if选择结构的语法: public class Demo{ public static void main(String[] ...

  5. 使用Scanner类

    import java.util.Scanner;   public class HelloWorld {     public static void main(String[] args) {   ...

  6. C# WPF发票打印

    微信公众号:Dotnet9,网站:Dotnet9.问题或建议,请网站留言: 如果您觉得Dotnet9对您有帮助,欢迎赞赏 C# WPF发票打印 内容目录 实现效果 业务场景 编码实现 本文参考 源码下 ...

  7. Miller-Rabin素数检测算法 acm模板

    Miller-Rabin素数检测算法 其基于以下两个定理. Fermat小定理 若n是素数,则∀a(a̸≡0(modn))\forall a(a \not\equiv 0 \pmod{n})∀a(a̸ ...

  8. 问题 E: Problem B

    #include <cstdio> #include <cstring> #include <algorithm> #include <vector> ...

  9. AC自动机(模板+例题)

    首先要明白AC自动机是干什么的: AC自动机其实就是一种多模匹配算法,那么你可能会问什么叫做多模匹配算法.下面是我对多模匹配的理解,与多模与之对于的是单模,单模就是给你一个单词,然后给你一个字符串,问 ...

  10. 小白月赛22 A : 操作序列

    A:操作序列 析题得说: 考察点 : 模拟,STL库容器的使用 坑点 : 区间不要搞丢东西 难点 : 这个题比较变态的是我们不知道每次输入每行是一个数还是两个数,就需要进行判断, 怎么判断呢?用 sc ...