An Easy Problem

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8371   Accepted: 5009

Description

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

Input

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.

Output

One integer per line, which is J.

Sample Input

1
2
3
4
78
0

Sample Output

2
4
5
8
83

Source

 
这题就是说给你一个1e6以内的数I,设x为I在二进制下1的个数.要找到大于n的最小的ans,满足ans在二进制下有x个1.
这一题我似乎是直接水过的...
如果看了Matrix67的帖子,就知道判断一个整数在二进制下有几个1只要O1的时间.
那么,我们不断的n++,判断一下就好了.最坏复杂度O(TI).
 #include<cstdio>
 using namespace std;
 int n,m,cnt;
 int calc(int x){
     x=(x&)+((x>>)&);
     x=(x&)+((x>>)&);
     x=(x&)+((x>>)&);
     x=(x&)+((x>>)&);
     x=(x&)+((x>>)&);
     return x;
 }
 int main(){
     while (scanf("%d",&n)&&n){
         cnt=calc(n),n++;
         while (calc(n)!=cnt) n++;
         printf("%d\n",n);
     }
     ;
 }

[poj 2453] 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. POJ 1152 An Easy Problem! (取模运算性质)

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

  3. POJ 2826 An Easy Problem? 判断线段相交

    POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...

  4. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  5. POJ 2826 An Easy Problem?![线段]

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12970   Accepted: 199 ...

  6. POJ 2826 An Easy Problem?! --计算几何,叉积

    题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...

  7. POJ 2826 An Easy Problem?! 好的标题

    受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...

  8. POJ 2826 An Easy Problem!(简单数论)

    Description Have you heard the fact "The base of every normal number system is 10" ? Of co ...

  9. 简单几何(线段相交) POJ 2826 An Easy Problem?!

    题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...

随机推荐

  1. 使用 node 创建代码服务器

    var express = require('express'); var proxy = require('http-proxy-middleware'); var app = express(); ...

  2. Gym 100247C Victor's Research(有多少区间之和为S)

    https://vjudge.net/problem/Gym-100247C 题意: 给出一串数,求有多少个区间的和正好等于S. 思路:计算处前缀和,并且用map维护一下每个前缀和出现的次数.这样接下 ...

  3. python学习 day05打卡

    今天可变学习的主要内容是 : 本节主要内容: 1.字典的简单介绍 2.字典增删改查和其他操作 3.字典的嵌套 一.字典的简单介绍 字典(dict)是pytho中唯一的一个映射类型.它是以{}括起来的键 ...

  4. C++中CopyFile、MoveFile的用法

    1.含义 CopyFile(A, B, FALSE);表示将文件A拷贝到B,如果B已经存在则覆盖(第三参数为TRUE时表示不覆盖) MoveFile(A, B);表示将文件A移动到B 2.函数原型 C ...

  5. _equipment

    该表控制切换地图自动更换装备,离开该地图时,装备自动切换为原来.,HEAD - TABARD小于0时取下装备,等于0时不更换,大于0时更换为对应装备. comment 备注 class 职业索引 1- ...

  6. _event_active

    EventId 事件ID GUID 对应creature或gameobject表中 guid,正数为生物,负数为物体 ActiveFlag 生物或物体激活时的flag,通常为0 NoticeText ...

  7. [原][qt]解决qt在vs下could not find or load the Qt platform plugin "windows" in ""问题

    在VS上开发qt遇到问题: 解决: 在main最开始加入: QTextCodec *xcodec = QTextCodec::codecForLocale(); QString exeDir = xc ...

  8. sort-桶排序

    void list_insert(list<int> &t,int num) { auto iter=t.begin(); for(;iter!=t.end();++iter) { ...

  9. 大数据新手之路四:联合使用Flume和Kafka

    Ubuntu16.04+Kafka1.0.0+Flume1.8.0 1.目标 ①使用Flume作为Kafka的Producer: ②使用Kafka作为Flume的Sink: 其实以上两点是同一个事情在 ...

  10. 对Maven项目进行强制更新

    选中项目 然后 选中Force Update of Snapshots/Releases,点击OK即可. 此时pom.xml就不会报错了.