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 ...
随机推荐
- [JZOJ4685] 【NOIP2016提高A组8.12】礼物
Description 夏川的生日就要到了.作为夏川形式上的男朋友,季堂打算给夏川买一些生日礼物.商店里一共有种礼物.夏川每得到一种礼物,就会获得相应喜悦值Wi(每种礼物的喜悦值不能重复获得).每次, ...
- boost::asio::io_service::定时器任务队列
使用io_service和定时器写的一个同步和异步方式的任务队列 #pragma once #include <string> #include <iostream> #inc ...
- java23种设计模式(三)单例模式
原文地址:https://zhuanlan.zhihu.com/p/23713957 一.概述 1.什么是单例模式? 百度百科是这样定义的:单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个 ...
- Redis真集群安装
Redis真集群安装 命令文档:http://redisdoc.com/index.html 下载:https://code.google.com/archive/p/redis/downloads ...
- jQuery插件图片懒加载lazyload
来自XXX的前言: 什么是ImageLazyLoad技术 在页面上图片比较多的时候,打开一张页面必然引起与服务器大数据量的 交互.尤其是对于高清晰的图片,占的几M的空间.ImageLazyLoad技术 ...
- 百万年薪python之路 -- 基础数据类型的补充练习
1.看代码写结果 v1 = [1,2,3,4,5] v2 = [v1,v1,v1] v1.append(6) print(v1) print(v2) [1,2,3,4,5,6] [[1,2,3,4,5 ...
- 从零开始把项目发布到maven仓库中心
sonatype准备操作 注册账号 https://issues.sonatype.org 1. 密码符号规范,并且工记住 新建项目 1. group id 如果你有com域名的所有权可以直接使用,如 ...
- Java设计模式_七大原则
简介 单一职责原则.对类来说,即一个类应该只负责一项职责. 开闭原则.对扩展开放,对修改关闭.在程序需要进行扩展的时候,不能去修改原有代码,使用接口和抽象类实现一个热插拔的效果. 里氏替换原则.任何基 ...
- Swift UIViewController中的delegate方式传值
ios swift开发中有几种方式传值,看到简书上一篇不错的文章. 链接:http://www.jianshu.com/p/3e1173652996 一.通过segue进行传值 二.通过delegat ...
- js创建子节点
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...