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 ...
随机推荐
- 创建优化的Go镜像文件以及踩过的坑
在Docker上创建Go镜像文件并不困难,但建立的文件很大,接近1G,使用起来不太方便.Docker镜像的一个主要难题就是如何优化,创建小的镜像.我们可以用多级构建的方法来创建Docker镜像文件,它 ...
- Python 命令行之旅:使用 docopt 实现 git 命令
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- 如何利用C# Roslyn编译器写一个简单的代码提示/错误检查?
OK, 废话不多说,这些天在写C#代码时突然对于IDE提示有了一些想法,之前也有了解过,不过并没有深入. 先看个截图: 一段再简单不过的代码了,大家注意看到 count 字段下面的绿色波浪线了吗,我们 ...
- (day29) 进程互斥锁 + 线程
目录 进程互斥锁 队列和堆栈 进程间通信(IPC) 生产者和消费者模型 线程 什么是线程 为什么使用线程 怎么开启线程 线程对象的属性 线程互斥锁 进程互斥锁 进程间数据不共享,但是共享同一套文件系统 ...
- Amazon S3数据存储
从官网下载aws 的unity插件,并做了简单修改(主要用修改PostObject),问题: (一)获取Pool ID 通过服务-Cognito-管理/新建用户池,可以新建或者获取Pool ID (二 ...
- vuex状态管理详细使用方法
1安装:vue ui或cnpm install vuex 2/使用import vuex from 'vuex' vue.use(vuex) var store = new Vuex.store({ ...
- 如何在Spring Boot中使用Cookies
一. 导读 本文大纲 读取HTTP Cookie 设置HTTP Cookie 读取所有Cookie[] 为Cookie设置过期时间 Https与Cookie HttpOnly Cookie 删除Coo ...
- 让你的sql开启氮气加速
事情的过程是:公司有一个上百行的sql 运行在MySQL数据库,速度奇慢无比,逻辑乱七八糟,我就不贴出来了,经过这次修改想总结一下如何写一个不被人骂的sql. 说一些被人诟病的问题: 一.子查询 把你 ...
- Python中的is和==的区别
Python中的is和==的区别 1. is 是比较内存地址id() a = "YongJie" b = "YongJie" print(id(a)) #233 ...
- 虚拟机linux centos7 查找ip不到的设置
1.centos7 系统后查找ip信息,不用ifconfig -a 命令,开始使用ip Addr命令 输入ip Addr 命令后,并没有看到实际的ip地址,记住上述图片中红色标记的ens32 这个就是 ...