ACM Same binary weight

时间:2022-11-05 09:45:22

Same binary weight

时间限制:300 ms  |  内存限制:65535 KB
难度: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
解题思路 1. 将右起第一个“01”,改变为“10” 2. 将该“01”后面的所有“1”移动至最后
#include <iostream>
#include <string>
#include <bitset>
#include <algorithm>
using namespace std; int main(){
int n;
while(cin >> n){
bitset<> bitInt(n);
string strInt =bitInt.to_string();
int pos = strInt.rfind("");
swap(strInt[pos],strInt[pos+]);
if(pos+ < ) sort(strInt.begin()+pos+,strInt.end());
cout<<bitset<>(strInt).to_ulong()<<endl;
}
}

string rfind("01")从字符串右边找”01“然后返回”01“的位置

将01后面的1移动到最后相当于对01后面的字符串排序



ACM Same binary weight的更多相关文章

  1. Same binary weight &lpar;位运算&rpar;

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

  2. nyoj 412 Same binary weight ()

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

  3. nyoj 412-Same binary weight &lpar;bitset &comma;to&lowbar;ulong&lpar;&rpar;&rpar;

    412-Same binary weight 内存限制:64MB 时间限制:0ms 特判: No 通过数:2 提交数:3 难度:3 题目描述: The binary weight of a posit ...

  4. 【ACM】Binary String Matching

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

  5. &lbrack;转&rsqb;XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks

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

  6. 论文翻译:Ternary Weight Networks

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

  7. caffeModels--models-caffes-大全

    caffe的伯克利主页:http://caffe.berkeleyvision.org/caffe的github主页:https://github.com/BVLC/caffe caffe的model ...

  8. nyoj412&lowbar;bitset&lowbar;

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

  9. &lbrack;综述&rsqb;Deep Compression&sol;Acceleration深度压缩&sol;加速&sol;量化

    Survey Recent Advances in Efficient Computation of Deep Convolutional Neural Networks, [arxiv '18] A ...

随机推荐

  1. &ast;&ast;Apache Options指令详解

    http://www.365mini.com/page/apache-options-directive.htm Options指令是Apache配置文件中一个比较常见也比较重要的指令,Options ...

  2. 网络处理1-异步GET请求

    前言 云计算 近几年来,云计算是一个非常热门的技术名词,很多专家认为,云计算会改变互联网的技术基础,甚至会影响整个产业的格局.可能还很多人不了解什么是云计算,简单来说,就是把用户的数据(比如文档.照片 ...

  3. &lbrack;C&num;&rsqb; c&num; 验证手机号码 最新的17手机号

    /// <summary> /// 校验手机号码是否符合标准. /// </summary> /// <param name="mobile"> ...

  4. The Apache HBase™ Reference Guide

    以下内容由http://hbase.apache.org/book.html#getting_started节选并改编而来. 运行环境:hadoop-1.0.4,hbase-0.94.22,jdk1. ...

  5. 2019-4-26 css学习笔记

    CSS简介:Cascading Style Sheets(层叠样式表)的缩写,它是一种用来表现HTML或XML等文件样式的计算机语言. CSS的作用:是定义网页外观(例如,字体.背景.文本.位置.布局 ...

  6. cefglue Flash

    用户计算机必须安装Adobe Flash组件才能播放动画,关于这点,找到3个解决方案: 方法一:安装NPAPI版本的Flash组件(非IE版)之后,才能播放动画.访问 http://get.adobe ...

  7. 2Q - Fibbonacci Number

    Your objective for this question is to develop a program which will generate a fibbonacci number. Th ...

  8. python &lowbar;、&lowbar;&lowbar;、&lowbar;&lowbar;xx&lowbar;&lowbar;之间的差别

    默认情况下,Python中的成员函数和成员变量都是公开的(public),在python中没有类public,private等关键词来修饰成员函数和成员变量.其实,Python并没有真正的私有化支持, ...

  9. SQL语句大全从基础到熟练(不含数据库高端操作)日常用户 三、

    前言 昨天晚上回家忘记带钥匙导致在楼下站街三小时,鬼天气热的不要不要的然后我就在车里坐了会之后就.....zzZZ,哈哈睡的挺香的毕竟累了一天了 上两篇文章都是介绍的语法语句,本篇文章介绍下函数的使用 ...

  10. C&num; 判断字符串为空有哪几种方法

    Length法:);Empty法:bool isEmpty = (str == String.Empty);General法:bool isEmpty = (str == ""); ...