nyoj 412-Same binary weight (bitset ,to_ulong())
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())的更多相关文章
- nyoj 412 Same binary weight ()
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
- ACM Same binary weight
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
- Same binary weight (位运算)
题目描述 The binary weight of a positive integer is the number of 1's in its binary representation.for ...
- nyoj 题目5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 待修改 nyoj 412 又是一个遗留问题
测试的数据都正确啊,跟别人正确代码也对比了一下,一直wrong ans,这道题是搞不定了,思路是这样的,一个int 的数, 例如 一个数的二进制是1001100,那么大于这个数的最小的有相同个数1的数 ...
- c++ bitset使用
A bitset is a special container class that is designed to store bits (elements with only two possibl ...
- [转]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 ...
- nyoj412_bitset_
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...
随机推荐
- 一文了解Mysql
文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. Redis系列到上一篇已经全部结束了,从本篇开始进入Mysql系列文章专题.本篇作为Mysql系列专题的开篇文 ...
- ArraryList源码解读
先由一道题引发思考: ArrayList list = new ArrayList(20);中的list扩充几次() A 0 B 1 C 2 D 3 答案:A 直接翻看 jd ...
- 实用---GUI的搭建,windowbuilder的使用
在进行GUI的搭建过程中,相信很多人对于一个图标的设置感觉写起来很麻烦,需要不断的添加,而在java中有一个windowbuilder窗口可以很好的帮助我们进行GUI的搭建 1.进入eclipse的页 ...
- Halcon一日一练:获取孔位
本例程是用于获取安装螺丝孔在图像中对应的坐标位置,并显示该坐标位,如上图所示. read_image(Image,'rim.png')//读取图像 dev_close_window()//关闭窗口 g ...
- python函数与异常处理
一.python函数 1.函数自定义格式: 分为有无返回值两种类型 def 函数名(): 代码语句 -------- -------- return 参数1,(参数2等)--------------- ...
- ArcGIS Engine空间查询功能的实现(QueryFilterClass+SpatialFilterClass)
地图中包含大量的信息,为了快速地了解所需信息,必须借助为空间数据专门编写的空间查询功能. 空间查询主要有两种类型: 基于属性的查询,也称为属性查询. 基于空间位置的查询,也称为空间查询. 查询类的基本 ...
- window下设置定时任务及基本配置
### window下设置定时任务及基本配置 轉載請註明出處: https://www.cnblogs.com/funnyzpc/p/11746439.html |****************** ...
- Kafka集群的安装和部署
一.Kafka的下载与解压 http://kafka.apache.org/downloads.html下载kafka_2.11-1.1.1.tgz.gz并解压到/home/jun下 [jun@mas ...
- SpringCloud之异常报警通知(八)
在之前整合降级的基础上,整合redis,达到报警的效果(redis的启动还是之前boot里面整合的redis) order-service pom.xml <dependency> < ...
- 一个普通类就能干趴你的springboot,你信吗?
先声明本人并不是标题党,如果看了本篇文章并且认为没有得到任何收获,请您随便留言骂我,本人绝不还口,已经对springboot了如指掌大大神,求放过! 不BB了,直接上代码,请各位在自己的springb ...