[POJ] 2453 An Easy Problem [位运算]
Description
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".
Input
A line containing a number "0" terminates input, and this line need not be processed.
Output
Sample Input
1
2
3
4
78
0
Sample Output
2
4
5
8
83
Source
#include<cstdio>
#include<algorithm> using namespace std; int main()
{
int p,x,num1,num2; while() {
num1=;num2=;
scanf("%d",&x);
if(!x) break;
p=x;
while(p>) {
if(p%!=) num1++;
p>>=;
}
while() {
x++;
p=x;
num2=;
while(p>) {
if(p%!=) num2++;
p>>=;
}
if(num2==num1) {
printf("%d\n",x);
break;
} }
} return ;
}
[POJ] 2453 An Easy Problem [位运算]的更多相关文章
- [poj 2453] An Easy Problem
An Easy Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8371 Accepted: 5009 D ...
- An easy problem (位运算)
[题目描述] 给出一个整数,输出比其大的第一个数,要求输出的数二进制表示和原数二进制表示下1的个数相同. [题目链接] http://noi.openjudge.cn/ch0406/1455/ [算法 ...
- An easy problem(位运算)
As we known, data stored in the computers is in binary form.(数据以二进制形式存储于电脑之中.)The problem we discuss ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- POJ 2826 An Easy Problem? 判断线段相交
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
- [poj]开关类问题 枚举 位运算
poj 1222 EXTENDED LIGHTS OUT 开关只有两种方案 按和不按,按两次相当于关 只用枚举第一排开关的按法即可,剩下的行为使上一排的灯全部关闭,按法可以确定,并且是唯一的. 最后 ...
- POJ 1166 The Clocks [BFS] [位运算]
1.题意:有一组3*3的只有时针的挂钟阵列,每个时钟只有0,3,6,9三种状态:对时针阵列有9种操作,每种操作只对特点的几个时钟拨一次针,即将时针顺时针波动90度,现在试求从初试状态到阵列全部指向0的 ...
随机推荐
- Unity GUI 用C#和Javascript写法的区别
以前都是用C#来写Unity的GUI.后来因为团队需要GUI必须用C#写. 其实一开始学Unity的GUI的时候我是想用C#来写,后来折腾了好久也没弄出来.反倒是这次不经意间就搞好了. C#和Java ...
- C++类的数组元素查找最大值问题
找出一个整型数组中的元素的最大值. /*找出一个整型数组中的元素的最大值.*/ #include <iostream> using namespace std; class ArrayMa ...
- Mysql 新建用户以及授权远程连接操作
1:以root身份登陆mysql终端 mysql -uroot -pmysql 2:创建wx用户,注意密码要加单引号 mysql> create user wx identified by 'w ...
- windows bat命令编写大全
1 echo 和 @ @ #关闭单行回显echo off #从下一行开始关闭回显 @echo off #从本行开始关闭回显.一般批处理第一行都是这个 echo on #从下一行开始打开回显 ec ...
- codility上的问题 (23)Chi 2012
这个题也比较有意思.意思是给定一个数组A,长度为M,里面都是正整数,代表每块地形的高度.现在要测试一种加农炮,给定一个炮弹的高度H, 如果存在最小的I,满足0 < I < M,满足A[I ...
- BZOJ1132: [POI2008]Tro
1132: [POI2008]Tro Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 815 Solved: 211[Submit][Status] ...
- Linux企业级项目实践之网络爬虫(17)——存储页面
在爬虫系统中数据的流量相当大,要处理的数据内容不仅包括爬虫系统的各种数据结构空间,而且包括从外部节点中得到的各种数据,比如HTTP请求,HTML页面,ROBOT.TXT等等.如果对这些内容处理不当,那 ...
- AzCopy – 上传/下载 Windows Azure Blob 文件
在我们收到的请求中,有一个频繁出现的请求是提供一种能在 Windows Azure Blob 存储与其本地文件系统之间轻松上传或下载文件的方法.一年半前, 我们很高兴地发布了 AzCopy, Wind ...
- <php>PDO用法一
<?php //造PDO对象 $pdo = new PDO("mysql:dbname=mydb;host=localhost","root"," ...
- Java集合之List
List(列表): List的特征是其元素以线性方式存储,集合中可以存放重复对象. List接口主要实现类包括: 1.ArrayList() : 代表长度可以改变的数组.可以对元素进行随机的访问,向A ...