描述

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>

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

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

NOI4.6 1455:An Easy Problem的更多相关文章

  1. 1455:An Easy Problem

    传送门:http://noi.openjudge.cn/ch0406/1455/ /-24作业 //#include "stdafx.h" #include<bits/std ...

  2. [openjudge] 1455:An Easy Problem 贪心

    描述As we known, data stored in the computers is in binary form. The problem we discuss now is about t ...

  3. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  4. An easy problem

    An easy problem Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  5. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  6. POJ 2826 An Easy Problem?!

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

  7. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  8. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  9. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. APK签名替换检测

    APK二次打包的危害 APK二次打包是Android应用安全风险中的一部分, 一般是通过反编译工具向应用中插入广告代码与相关配置,再在第三方应用市场.论坛发布.打包党对移动App带来的危害有以下几种: ...

  2. 洛谷——P1305 新二叉树(新建二叉树以及遍历)

    题目描述输入一串二叉树,用遍历前序打出. 输入输出格式输入格式: 第一行为二叉树的节点数n.(n \leq 26n≤26) 后面n行,每一个字母为节点,后两个字母分别为其左右儿子. 空节点用*表示 输 ...

  3. 一个APP从启动到主页面显示经历了哪些过程?

    ①点击桌面App图标,Launcher进程采用Binder IPC向system_server进程发起startActivity请求: ②system_server进程接收到请求后,向zygote进程 ...

  4. spring定时器时间设置规则

    单纯针对时间的设置规则org.springframework.scheduling.quartz.CronTriggerBean允许你更精确地控制任务的运行时间,只需要设置其cronExpressio ...

  5. springBoot 集成redis客户端傻瓜式流程

    Redis目前作为很多项目的主流缓存方案,学习完redis的基本命令和特性后.我们要集成进我们的springboot项目中 不废话上代码 在application.yml中加入 spring: red ...

  6. DataX-MysqlReader 插件文档

    :first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdow ...

  7. 从桌面到 Web - 二十几天学 ASP.NETCore 1

    这么多年一直从事桌面开发,一直没有时间好好学学  web 开发.感觉自己就像从石器时代走来的古代类人猿.由于工作的调整,现在终于有时间学习一下 Web 开发.出于对技术和框架的熟悉和继承,决定还是学习 ...

  8. 01_垂直居中body中的应用

    1: 应用场景 在body中书写一个代码块, 使其相对于body垂直居中 <!DOCTYPE html> <html lang="en"> <head ...

  9. 14.python案例:爬取电影天堂中所有电视剧信息

    1.python案例:爬取电影天堂中所有电视剧信息 #!/usr/bin/env python3 # -*- coding: UTF-8 -*- '''======================== ...

  10. React实现座位排布组件

    React实现座位排布组件 最近在开发一个影院系统的后台管理系统,该后台可以设置一个影厅的布局. 后台使用的是react框架,一位大神学长在几天之内就把这个控件研究出来了,并进行了较为严密的封装,佩服 ...