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 ...
随机推荐
- MobaXterm 使用中间服务器
经常需要连接服务器,但是有时候服务器需要经过一层中间服务器才可以连接,所以本文告诉大家如何使用MobaXterm 配置中间服务器,进行ssh连接 在本文的开始,本地转发服务器已经弄好,本文不会告诉大家 ...
- 改变this指向
fn.call(obj,参数,参数): call(函数执行过程中this指向,后面的参数就是原函数的参数列表) : 函数下的一个内置方法,当我们申明一个函数的时候,这个函数下就会有一个默认的方法,ca ...
- 新书《iOS编程(第6版)》抢鲜试读
我最近翻译了Big Nerd Ranch的<iOS编程(第6版)>.我用了大半年时间,尽可能做到通顺易懂.不足之处请大家多多指正.感谢辛苦审校的丁道骏同学. 这本书得过Jolt大奖,原书在 ...
- Team Foundation Server 2015使用教程【10】:团队项目删除
- Team Foundation Server 2015使用教程【3】:默认团队成员连接tfs及checkin操作
- 彻底搞懂HTML5文件上传操作需要的相关资料
https://developer.mozilla.org/zh-CN/docs/Web/GuideMDN Web Guide https://developer.mozilla.org/zh-CN/ ...
- 解读中兴通信在物联网行业如何践行DDD
此前,在由 ThoughtWorks 举办的领域驱动设计峰会 DDD-China 2019 上,InfoQ 记者就开发团队为何需要 DDD.目前业界实践 DDD 的挑战等问题对中兴通讯资深软件架构师张 ...
- TestStand 基本设置
1. 过程模型设置 菜单->Configure->Station Options->Model TestStand 默认提供了三种过程模型 Sequential.Batch.Para ...
- rest_framework框架之认证功能的使用和源码实现流程分析
rest_framework框架之认证的使用和源码实现流程分析 一.认证功能的源码流程 创建视图函数 Note 创建视图函数后,前端发起请求,url分配路由,执行视图类,视图类中执行对应方法必须经过d ...
- 「CF1082C」Multi-Subject Competition 解题报告
人生第一篇题解,虽然这道题做的人暂时不多,但我相信它--迟早有一天会发扬光大的!!! 说完废话 步入正题 题意: 传送门 思路: 模拟.枚举 对于每个组里的数字,先排序,然后从一到最大可能的情况,枚举 ...