an easy problem(贪心)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8333 | Accepted: 4986 |
Description
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
A line containing a number "0" terminates input, and this line need not be processed.
Output
Sample Input
1
2
3
4
78
0
Sample Output
2
4
5
8
83
Source
// Presentation Error(展示错误orz) mlgb没换行符报错 第一次出现这种错误整个人都蒙圈了
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int er[];
int main()
{
int n;
while(cin>>n&& n)//当能输出且不为零时
{
int k=,tot=;
memset(er,,sizeof(er));
while(n)//计算二进制
{
er[++k]=n%;
n/=;
}
k++;
for(int i=;i<=k;i++)
{
if(er[i]==)//找1的个数
{
tot++;
er[i]=;
if(er[i+]==)//从低位到高位找01
{
er[i+]=;//找到了就改为1; 相当于左移了
break;
}
}
}
for(int i=;i<=tot-;i++)
{
er[i]=;//将tot-1个1放在末尾,(右移),tot-1是因为其中一个左移了
}
int sum=;
for(int i=k;i>=;i--)//将二进制转换为十进制输出
{
sum=sum*+er[i];
}
printf("%d\n",sum);
}
return ;
}
an easy problem(贪心)的更多相关文章
- [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 ...
- 一本通 1223:An Easy Problem
\[传送门qwq\] [题目描述] 给定一个正整数N,求最小的.比N大的正整数M,使得M与N的二进制表示中有相同数目的1. 举个例子,假如给定的N为78,其二进制表示为1001110,包含4个1,那么 ...
- 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 ...
- 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,又因为每 ...
随机推荐
- iOS 4.5.5版本 被拒绝!!!! "App Rejected : non-public APIs"
今天上午收到邮件说是被拒绝了 原文是 这一版本 我就添加一个购买sku的方法, 并没有添加什么库 ,简简单单的一次升级给我出一私有方法拒绝!!!!! 在xcode8 iOS10 刚出来 ,苹果新规则 ...
- 每天一个Linux命令(60)ip命令
ip命令是Linux下较新的功能强大的网络配置工具. (1)用法: 用法: ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]] ...
- 028_MapReduce中的计数器Counter的使用
一.分析运行wordcount程序屏幕上打印信息 ##运行wordcount单词频率统计程序,基于输出输出路径. [hadoop@hadoop-master hadoop-1.2.1]$ hadoop ...
- centos磁盘安装与磁盘分区方案
概述 关于centos分区的相关知识 无论怎么分区并不会影响系统文件目录的布局,如果只分/和swap这两个区 没有 usr , var , etc 等分区,在安装好后文件根目录里依然会有usr , v ...
- 关于Class.getResourceAsStream
Properties properties = new Properties(); properties.load(new InputStreamReader(CharactorTest.cl ...
- hadoop程序在本地模式调试作业
1.首先下载cygwin,例如安装在该目录下,D:\Program Files\cygwin\ 2.copy linux上的jar包到D:\Program Files\cygwin\home\lib ...
- 20145231 《Java程序设计》第一周学习总结
20145231 <Java程序设计>第一周学习总结 教材学习内容总结 Java三大平台Java SE,Java EE,Java ME.其中,Java SE是我们学习的基础. Java S ...
- Android LCD(二):常用接口原理篇【转】
本文转载自:http://blog.csdn.net/xubin341719/article/details/9125799 关键词:Android LCD TFT TTL(RGB) LVDS E ...
- 关于图片上传与下载(Java)
图片的上传 package com.upload; import java.io.IOException;import java.io.PrintWriter; import javax.servle ...
- EntityFramework 学习 一 Execute Native SQL Query
SQL query for entity types: using (var ctx = new SchoolDBEntities()) { var studentList = ctx.Student ...