412-Same binary weight

内存限制:64MB
时间限制:0ms
特判: No

通过数:2
提交数:3
难度:3

题目描述:

The binary weight of a positive  integer is the number of 1's in its binary representation.for example,the decmial number 1 has a binary weight of 1,and the decimal number 1717 (which is 11010110101 in binary) has a binary weight of 7.Give a positive integer N,return the smallest integer greater than N that has the same binary weight as N.N will be between 1 and 1000000000,inclusive,the result is guaranteed to fit in a signed 32-bit interget.

输入描述:

The input has multicases and each case contains a integer N.

输出描述:

For each case,output the smallest integer greater than N that has the same binary weight as N.

样例输入:

复制

1717
4
7
12
555555

样例输出:

1718
8
11
17
555557

C/C++  AC:

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <bitset>
#define PI 3.1415926 using namespace std;
const int MY_MAX = ;
int N, M; int main()
{
while (cin >>N)
{
bitset <> A(N);
int pos = , cnt = ;
for (int i = ; i <= ; ++ i)
{
if (A[i] && !A[i + ])
{
A[i] = , A[i + ] = ;
pos = i;
break;
}
if (A[i])
cnt ++;
} for (int i = ; i < pos; ++ i)
{
if (cnt)
{
A[i] = ;
cnt --;
}
else
A[i] = ;
}
printf("%d\n", A.to_ulong());
}
}

nyoj 412-Same binary weight (bitset ,to_ulong())的更多相关文章

  1. nyoj 412 Same binary weight ()

    Same binary weight 时间限制:300 ms  |  内存限制:65535 KB 难度:3   描述 The binary weight of a positive  integer ...

  2. ACM Same binary weight

    Same binary weight 时间限制:300 ms  |  内存限制:65535 KB 难度:3   描述 The binary weight of a positive  integer ...

  3. Same binary weight (位运算)

    题目描述 The binary weight of a positive  integer is the number of 1's in its binary representation.for ...

  4. nyoj 题目5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  5. 待修改 nyoj 412 又是一个遗留问题

    测试的数据都正确啊,跟别人正确代码也对比了一下,一直wrong ans,这道题是搞不定了,思路是这样的,一个int 的数, 例如 一个数的二进制是1001100,那么大于这个数的最小的有相同个数1的数 ...

  6. c++ bitset使用

    A bitset is a special container class that is designed to store bits (elements with only two possibl ...

  7. [转]XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks

    感谢: XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks XNOR-Net ImageNet Cl ...

  8. 论文翻译:Ternary Weight Networks

    目录 Abstract 1 Introduction 1.1 Binary weight networks and model compression 2 Ternary weight network ...

  9. nyoj412_bitset_

    Same binary weight 时间限制:300 ms  |  内存限制:65535 KB 难度:3   描述 The binary weight of a positive  integer ...

随机推荐

  1. 不安分的管家——Jenkins

    占个位,持续补充. 一.使用Jenkins进行自动化部署 一直以来关于xx框架/中间件的技术博客有个奇怪的事情.这类文章特点大而全,重复率高,读者阅读完毕基本从安装到放弃. 作为一个使用者,我只是为了 ...

  2. pycharm在进行debug时不小心把console关闭了,恢复console的办法

    点击下图中右边的箭头就恢复了 此时可看到console已恢复

  3. url中常见符号说明

    如:http://10.1.1.71:9999/auditcenter/api/v1/auditPlanList?pageSize=20&page=1 ?:分隔实际的url和参数 & ...

  4. python-url中中文编码与解码

    接口测试中遇到这种情况:get请求的传参有中文,以致url中有中文编码. 下面是常见的一种编码解码方式: from urllib.request import quote, unquote url = ...

  5. Java类型信息(RTTI和反射)

    要想在IT领域站得住脚,必须得不断地学习来强化自己,但是学过的技术不实践很容易便被遗忘,所以一直都打算开个博客,来记录自己学的知识,另外也可以分享给有需要的人! 最近在学习反射,为了更好地理解反射,就 ...

  6. PAT-1022 Digital Library (30 分) 字符串处理

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  7. 三、DockerFile 定制属于自己的专属镜像

    前言 上篇文章我们知道了怎么操作镜像和容器,到基础都是从已经存在的镜像开始的,那我们自己怎样搭建一个镜像并使用它呢?接下来就让我们学习使用dockerfile 创建属于自己的镜像吧. dockerfi ...

  8. laravel6.0控制器-资源控制器

    控制器:控制器用来处理业务的,不应该处理逻辑,如果是小项目可以把逻辑写到控制器里,大点的项目应该抽离出来业务处理层如下:services业务处理层:比如:获取值,验证值,异常捕获命名规则:控制器名:用 ...

  9. ElasticSearch head插件安装与配置

    下载 下载地址:https://github.com/mobz/elasticsearch-head 安装 1. 下载到本地 git clone 2. 安装 grunt npm install -g ...

  10. (Java) RedisUtils

    package com.vcgeek.hephaestus.utils; import org.springframework.beans.factory.annotation.Autowired; ...