NOI4.6 1455:An Easy Problem
描述
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的更多相关文章
- 1455:An Easy Problem
传送门:http://noi.openjudge.cn/ch0406/1455/ /-24作业 //#include "stdafx.h" #include<bits/std ...
- [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 ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- navicat for mysql连接本地数据库
navicat for mysql连接本地数据库 打算使用navicat连接本地数据库,连接的时候,一直连接不上.然后猜想是不是本地数据库没有设置好.输入mysql,出错内容:access denie ...
- centos7 teamviewer
Step 1: Install the prerequisites. # yum install glibc alsa-lib freetype libICE libSM libX11 libXau ...
- vs2019 解决方案加载报错
1. 如图 解决方案: 1.先关闭vs: 2.把C:/Users/<users name>/AppData/Local/Microsoft/VisualStudio/14.0/Compon ...
- MySQL 命令行(转)
1.登录mysql 本地:mysql -u root -p, 回车后输入密码; 也可以p后不加空格,直接加密码.回车就登录了 远程:mysql -hxx.xx.xx.xx -u -pxxx 2.查看数 ...
- windows键的妙用
(1)当你需要暂时离开电脑一会儿,怕其余人动你的电脑时,你只需要按windows键+L就可以了,当然前提是你给自己的电脑设置过开机密码. (2)有时候你需要在盘里边找某个文件,但你的桌面上密密麻麻的, ...
- DynamoDB的基本操作(一)
一.创建表 1 var AWS = require("aws-sdk"); 2 AWS.config.update({ 3 region: "us-west-2" ...
- 【一起学源码-微服务】Nexflix Eureka 源码七:通过单元测试来Debug Eureka注册过程
前言 上一讲eureka client是如何注册的,一直跟到源码发送http请求为止,当时看eureka client注册时如此费尽,光是找一个regiter的地方就找了半天,那么client端发送了 ...
- Web基础了解版10-Filter-Listener
Filter 对于WEB应用来说,过滤器是一个驻留在服务器中的WEB组件,他可以截取客户端和WEB资源之间的请求和响应信息. 在一个WEB应用中可以部署多个过滤器,多个过滤器就组成了一个过滤器链,请求 ...
- 最小生成树+LCA不能算最小环!!!!!!!
- Gif动图压缩java版
简单说明下,如果不是压缩动图的话只用java本身的包足够实现压缩和截取图片了,为了能够压缩gif动图,这里引用了两个文件 AnimatedGifEncoder 和 GifDecoder, 先用Deco ...