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. [UVA-11039]Children's Game

    解析 微扰法贪心经典题 代码 #include <bits/stdc++.h> using namespace std; bool cmp(const string &x, con ...

  2. Thymeleaf 模板引擎技术

    引入Thymeleaf: <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf. ...

  3. Python.错误解决:scrapy 没有crawl 命令

    确保2点: 1.把爬虫.py复制到spiders文件夹里 如执行scrapy crawl demo ,spiders里面就要有demo.py文件 2.在项目文件夹内执行命令 在scrapy.cfg所在 ...

  4. SpringBoot学习路线

    网上也有很多github资源,都是自己学习Spring Boot时候,自己练的代码 虽然现在最新的版本用2.1.3.RELEASE版本,以前版本的demo运行可能会遇到错误.但是有总比没有要好,不是么 ...

  5. Hibernate的查询功能

    1.Query对象 1.使用Query对象,不需要写sql语句,但是写hql语句 (1)hql:hibernate query language,提供查询语言,这个hql语言和普通sql语句相似 (2 ...

  6. Java离线人脸识别SDK 支持arcface 2.0 最新版

    虹软人脸识别SDK之Java版,支持SDK 1.1+,以及当前最新版本2.0,滴滴,抓紧上车! JDK SDK Win release license status 前言 由于业务需求,最近跟人脸识别 ...

  7. js常见知识点3.面向对象之继承、设计模式

    一.面向对象的三大特征 建议回复: 封装:屏蔽内部细节.调用外部接口实现对应功能(函数调用) 继承:子类继承父类中的属性和方法 多态(js中不存在多态的概念) 二.继承 建议回复: 继承:子类继承父类 ...

  8. Oracle DB , 计算各个用户/schema 的磁盘占用空间

    http://www.dba-oracle.com/t_find_size_schema.htm Question:  How do I find the size of a schema in my ...

  9. MySQL official tutorial

    1.installation 2.setup environment variables add %/MySQL Server/bin to path. then restart cmd/powers ...

  10. HTML第五章总结

    A Chapter for <img> 前言 这一章讲了 Web 图片 format 的各自的优缺点和elements of 's attributes. Section1:Q1:How ...