描述

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".

输入

One integer per line, which is I (1 <= I <= 1000000).

A line containing a number "0" terminates input, and this line need not be processed.

输出

One integer per line, which is J.

样例输入1

2

3

4

78

0
样例输出2

4

5

8

83 题目大意: 一个2进制数,比如5------101 共有两个1,找一个比其大的,并且其二进制数也有一样多个1的最小数

这问题用枚举,就是一道Easy Problem,一直用函数枚举,很轻松~~~~~  代码如下:

<span style="font-size:12px;BACKGROUND-COLOR: #ffff99">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int find(int x)
{
int a=0;
while(x)
{
if(x%2)
a++;
x/=2;
}
return a;
}
int main()
{
int n,a=0;
scanf("%d",&n);
while(n)
{
a=0;
int x=n;
while(x)
{
if(x%2)
a++;
x/=2;
}
for(n++;;n++)
if(find(n)==a)
{
printf("%d\n",n);
break;
}
scanf("%d",&n);
}
}</span>

因为有多组数据,所以记得清零

可以,这很贪心,哈哈哈哈哈哈哈!

最新文章

  1. HBase+Phoenix整合入门--集群搭建
  2. 关于C#开发WEB项目TextBox控件的自适应高问题解决办法!
  3. 使用Topshelf 开发windows服务
  4. MySQL数据库学习笔记(八)----JDBC入门及简单增删改数据库的操作
  5. Unicode : RLO
  6. Linux内核2.4.x的网络接口源码的结构[转]
  7. MySQL 中随机抽样:order by rand limit 的替代方案
  8. php获取系统信息的方法
  9. iOS 必备技术点
  10. 字符串数组越界bug(2)
  11. 距离顶部估计像素,显示div!
  12. Java与C++相异的地方
  13. Android4.0设置界面改动总结(三)
  14. C# 隐藏 Windows Phone 侦错模式中萤幕右上角的数据条(模拟器、实机可用),截图好方便。
  15. C++ 头文件系列(string)----分析string初始化内存模型
  16. nodejs6下使用koa2
  17. spring整合springmvc和hibernate
  18. EXT JS认识EXTJS,第一个EXTJS例子
  19. 在Docker中体验数据库之Microsoft SQL Server
  20. NTFS权限和共享权限的区别

热门文章

  1. js简单实现promise
  2. Spring Tool Suite记录
  3. Resharper 去掉注释拼写
  4. 使用IDEA创建基于Maven SpringMvc项目
  5. Vijos1035 贪婪的送礼者 [map的应用]
  6. requests库结合selenium库共同完成web自动化和爬虫工作
  7. [梁山好汉说IT] 如何理解一致性Hash
  8. Spring Boot 整合 slf4j+log4j2 实现日志管理
  9. 深度探索c++对象模型阅读笔记图
  10. TensorFlow之tf.less()