ACM Same binary weight
Same binary weight
- 描述
-
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的更多相关文章
- Same binary weight (位运算)
题目描述 The binary weight of a positive integer is the number of 1's in its binary representation.for ...
- nyoj 412 Same binary weight ()
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
- nyoj 412-Same binary weight (bitset ,to_ulong())
412-Same binary weight 内存限制:64MB 时间限制:0ms 特判: No 通过数:2 提交数:3 难度:3 题目描述: The binary weight of a posit ...
- 【ACM】Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- [转]XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks
感谢: XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks XNOR-Net ImageNet Cl ...
- 论文翻译:Ternary Weight Networks
目录 Abstract 1 Introduction 1.1 Binary weight networks and model compression 2 Ternary weight network ...
- caffeModels--models-caffes-大全
caffe的伯克利主页:http://caffe.berkeleyvision.org/caffe的github主页:https://github.com/BVLC/caffe caffe的model ...
- nyoj412_bitset_
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
- [综述]Deep Compression/Acceleration深度压缩/加速/量化
Survey Recent Advances in Efficient Computation of Deep Convolutional Neural Networks, [arxiv '18] A ...
随机推荐
- Hybrid App是如何实现网页语言与程序语言的混合?谁占主体?
[编者按]本文作者@徐珂铭,一位看好Html5的移动互联网的从业人士.喜爱玩技术,会点JAVA.HTML及CSS,有自己的想法及姑且能表达想法的文字,因此有了自己的文章. 基于HTML5的Web Ap ...
- 运维自动化之ansible的安装与使用(包括模块与playbook使用)(转发)
原文 http://dl528888.blog.51cto.com/2382721/1435415 我使用过puppet(地址是http://dl528888.blog.51cto.com/2382 ...
- angularjs实战
1.指令 transclude 保留原来的内容 replace 去掉<my-directive>指令 <script src="http://apps.bdimg.com ...
- bootstrap 入门
bootstrap 入门 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&q ...
- php几个常用的概率算法(抽奖、广告首选)
做网站类的有时会弄个活动什么的,来让用户参加,既吸引用户注册,又提高网站的用户活跃度.同时参加的用户会获得一定的奖品,有100%中奖的,也有按一定概率中奖的,大的比如中个ipad.iphone5,小的 ...
- windows OBJECT查找
PspCidTable表里.索引值总之4的倍数.也就是说 PID/4 才是PspCidTable索引.*8 才是PsPCidTable+偏移.获取进程对应的 _HANDLE_TABLE_ENTRY 结 ...
- js Array对象
http://www.w3cschool.cc/js/js-obj-array.html 创建新方法 原型是JavaScript全局构造函数.它可以构建新Javascript对象的属性和方法. 实例: ...
- DSP using MATLAB示例Example3.16
代码: b = [0.0181, 0.0543, 0.0543, 0.0181]; % filter coefficient array b a = [1.0000, -1.7600, 1.1829, ...
- DOM--3 DOM核心和DOM2 HTML(1)
网页是一种结构化的文档,使用一组预定义的XML和HTML标签进行标记:当浏览器接受到网页文档时,会根据文档类型和关联的样式表对其进行解析,然后以可视化形式显示在屏幕上. DOM是一组用来描述脚本怎样与 ...
- 20145223《Java程序程序设计》第9周学习总结
20145223<Java程序设计>第9周学习总结 教材学习内容总结 第十六章:整合数据库 JDBC入门 1.JDBC简介: 2.JDBC主要分成两个部分,JDBC应用程序开发者接口和JD ...