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 ...
随机推荐
- 【53.57%】【codeforces 610C】Harmony Analysis
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- HDU1166 敌兵布阵 BZOJ1012 最大数[树状数组]
一.前置知识-树状数组 树状数组(binary indexed tree)是一种简洁的代码量很小的数据结构,能够高效的处理前缀区间上的问题.在很多情况下能写树状数组解决的就不用码半天线段树了. 树状数 ...
- 【Linux】一个定时任务小脚本
需要一个定时任务,每隔固定时间停止,等待几分钟,然后在启动,每5分钟一个循环. 简要写了一下,如下,未来在优化: 3,8,13,18,23,28,33,38,43,48,53,58 * * * * s ...
- Python3 安装pylint 及与PyCharm关联
使用如下命令: pip3 install pylint 安装完后可以看到在你的python3的目录底下的Scripts目录下有pylint.exe了 然后就可以使用pylint 评估你的代码了,如: ...
- 以windows服务方式快速部署免安装版Postgres数据库
目录 以windows服务方式快速部署免安装版Postgres数据库 1.下载Postgresql数据库免安装包 2.安装环境准备及验证 解压文件 测试环境依赖 3.创建并初始化数据目录 创建数据目录 ...
- Excel基本功能
公式基础: 比较运算符的种类 flase对应0 而ture对应1 连接运算 利用之前提到的ture就是1 乘以100 注意用括号区分优先级 函数应用基础: 系统已经列好这几个常用的函数 右键单击状态栏 ...
- Alibaba Cloud Toolkit 使用心得(IDEA版)
一.安装插件 确保 IntelliJ IDEA 在 2018.1 或更高版本 打开 Settings - Plugins 搜索安装 Alibaba Cloud Toolkit 二.配置环境 Deplo ...
- XAMPP下MYSQL中文乱码问题的解决
XAMPP下MYSQL中文乱码问题的解决 现象描述: 安装完成XAMMP后,内置有MySQL数据库. 新建好自己的数据库后通过hibernate往表里面添加一些中文信息时全部乱码变成“??”. 问题解 ...
- mysqldump主从复制
一,主从复制条件 1,开启binlog功能2,主库建立同步账号3,从库配置master.info(change mast..)4,start slave复制开关知识点:####1, 3个线程,主库i ...
- 「Vijos 1284」「OIBH杯NOIP2006第二次模拟赛」佳佳的魔法阵
佳佳的魔法阵 背景 也许是为了捕捉猎物(捕捉MM?),也许是因为其它原因,总之,佳佳准备设计一个魔法阵.而设计魔法阵涉及到的最关键问题,似乎就是那些带有魔力的宝石的摆放-- 描述 魔法阵是一个\(n ...