c++ std::bitset

http://blog.csdn.net/qll125596718/article/details/6901935#include <iostream>#include <stdint.h>#include <bitset>using namespace std;

int main() {    for(uint64_t i=0; i<64; i++){       bitset<64> bs;       //uint64_t j = (uint64_t)1 << i;       bs.set(i);       cout << i << ": " << bs << "," << bs.to_ulong() << endl;    }    return 0;}

0: 0000000000000000000000000000000000000000000000000000000000000001,11: 0000000000000000000000000000000000000000000000000000000000000010,22: 0000000000000000000000000000000000000000000000000000000000000100,43: 0000000000000000000000000000000000000000000000000000000000001000,84: 0000000000000000000000000000000000000000000000000000000000010000,165: 0000000000000000000000000000000000000000000000000000000000100000,326: 0000000000000000000000000000000000000000000000000000000001000000,647: 0000000000000000000000000000000000000000000000000000000010000000,1288: 0000000000000000000000000000000000000000000000000000000100000000,2569: 0000000000000000000000000000000000000000000000000000001000000000,51210: 0000000000000000000000000000000000000000000000000000010000000000,102411: 0000000000000000000000000000000000000000000000000000100000000000,204812: 0000000000000000000000000000000000000000000000000001000000000000,409613: 0000000000000000000000000000000000000000000000000010000000000000,819214: 0000000000000000000000000000000000000000000000000100000000000000,1638415: 0000000000000000000000000000000000000000000000001000000000000000,3276816: 0000000000000000000000000000000000000000000000010000000000000000,6553617: 0000000000000000000000000000000000000000000000100000000000000000,13107218: 0000000000000000000000000000000000000000000001000000000000000000,26214419: 0000000000000000000000000000000000000000000010000000000000000000,52428820: 0000000000000000000000000000000000000000000100000000000000000000,104857621: 0000000000000000000000000000000000000000001000000000000000000000,209715222: 0000000000000000000000000000000000000000010000000000000000000000,419430423: 0000000000000000000000000000000000000000100000000000000000000000,838860824: 0000000000000000000000000000000000000001000000000000000000000000,1677721625: 0000000000000000000000000000000000000010000000000000000000000000,3355443226: 0000000000000000000000000000000000000100000000000000000000000000,6710886427: 0000000000000000000000000000000000001000000000000000000000000000,13421772828: 0000000000000000000000000000000000010000000000000000000000000000,26843545629: 0000000000000000000000000000000000100000000000000000000000000000,53687091230: 0000000000000000000000000000000001000000000000000000000000000000,107374182431: 0000000000000000000000000000000010000000000000000000000000000000,214748364832: 0000000000000000000000000000000100000000000000000000000000000000,429496729633: 0000000000000000000000000000001000000000000000000000000000000000,858993459234: 0000000000000000000000000000010000000000000000000000000000000000,1717986918435: 0000000000000000000000000000100000000000000000000000000000000000,3435973836836: 0000000000000000000000000001000000000000000000000000000000000000,6871947673637: 0000000000000000000000000010000000000000000000000000000000000000,13743895347238: 0000000000000000000000000100000000000000000000000000000000000000,27487790694439: 0000000000000000000000001000000000000000000000000000000000000000,54975581388840: 0000000000000000000000010000000000000000000000000000000000000000,109951162777641: 0000000000000000000000100000000000000000000000000000000000000000,219902325555242: 0000000000000000000001000000000000000000000000000000000000000000,439804651110443: 0000000000000000000010000000000000000000000000000000000000000000,879609302220844: 0000000000000000000100000000000000000000000000000000000000000000,1759218604441645: 0000000000000000001000000000000000000000000000000000000000000000,3518437208883246: 0000000000000000010000000000000000000000000000000000000000000000,7036874417766447: 0000000000000000100000000000000000000000000000000000000000000000,14073748835532848: 0000000000000001000000000000000000000000000000000000000000000000,28147497671065649: 0000000000000010000000000000000000000000000000000000000000000000,56294995342131250: 0000000000000100000000000000000000000000000000000000000000000000,112589990684262451: 0000000000001000000000000000000000000000000000000000000000000000,225179981368524852: 0000000000010000000000000000000000000000000000000000000000000000,450359962737049653: 0000000000100000000000000000000000000000000000000000000000000000,900719925474099254: 0000000001000000000000000000000000000000000000000000000000000000,1801439850948198455: 0000000010000000000000000000000000000000000000000000000000000000,3602879701896396856: 0000000100000000000000000000000000000000000000000000000000000000,7205759403792793657: 0000001000000000000000000000000000000000000000000000000000000000,14411518807585587258: 0000010000000000000000000000000000000000000000000000000000000000,28823037615171174459: 0000100000000000000000000000000000000000000000000000000000000000,57646075230342348860: 0001000000000000000000000000000000000000000000000000000000000000,115292150460684697661: 0010000000000000000000000000000000000000000000000000000000000000,230584300921369395262: 0100000000000000000000000000000000000000000000000000000000000000,461168601842738790463: 1000000000000000000000000000000000000000000000000000000000000000,9223372036854775808
时间: 2024-10-26 04:41:51

c++ std::bitset的相关文章

HDU 4920 Matrix multiplication(std::bitset)

题目连接 :http://acm.hdu.edu.cn/showproblem.php?pid=4920 题意 :给两个n*n的矩阵A.B,要求算的A*B (答案对3取模) (比赛的时候一直想不到怎么去消复杂度,在最后的时候想到了用三进制压几位状态(就是几位几位算)应该可以过的,可是敲完比赛也结束.(压6位是可以过的) 正解是bitset搞,第一次接触到bitset这个神器,用起来确实很炫酷. 方法是统计A矩阵mod3后1出现在哪些位置,2出现哪些位置,B也一样,只是A是以一行为一个“状态”,

【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

有两辆车,容量都为K,有n(10w)个人被划分成m(2k)组,依次上车,每个人上车花一秒.每一组的人都要上同一辆车,一辆车的等待时间是其停留时间*其载的人数,问最小的两辆车的总等待时间. 是f(i,j)表示前i组,j个人是否可行.w(i)表示第i组的人数. if f(i,j)==1 then f(i+1,j+w(i+1))=1. 这是个bitset可以做的事情,每次左移以后或上f(i-1)的bitset即可.其实可以滚动数组. 然后每更新一次bitset,求一下其最左侧的1的位置,就是对于第一辆

#include &lt;bitset&gt;

1 none();测试是否有越位 2 reset();全部清零 3 set(7, 0);把第7个字符改成0,操作二进制位 4 to_string();转换为字符串 5 to_ulong();转换为无符号整数 bitset可以实现把十进制转换为二进制,以及输出补码 1 #include <iostream> 2 #include <bitset> 3 4 void main() 5 { 6 int num = -5; 7 8 std::bitset<32>myset(nu

bitset

bitset这个东西,是c++里面封装好了的处理多位运算的东西. 亲测比自己写快10倍以上. 以下是概念: std::bitset是STL的一部分,准确地说,std::bitset是一个模板类,它的模板参数不是类型,而整形的数值(这一特性是ISO C++2003的新特性),有了它我们可以像使用数组一样使用位.下面看一个例子: #include<bitset> std::bitset<8> bs;//它是一个模板,传递的参数告诉编译器bs有8个位. 我们接着看上面的代码,通过上面两行

[luoguP2447] [SDOI2010]外星千足虫(高斯消元 + bitset)

传送门 用bitset优化,要不然n^3肯定超时 消元过程中有几点需要注意,找到最大元后break,保证题目中所说的K最小 如果有自由元说明解很多,直接返回 #include <bitset> #include <cstdio> #define N 2050 #define max(x, y) ((x) > (y) ? (x) : (y)) int n, m, ans; std::bitset <N> s[N]; char S[N][N]; inline int

Bitset小结 (POJ2443 &amp; HDU4920)

学了下bitset用法,从网上找的一些bitset用法,并从中调出一些常用的用法. 构造函数bitset<n> b; b有n位,每位都为0.参数n可以为一个表达式.如bitset<5> b0;则"b0"为"00000"; bitset<n> b(unsigned long u); b有n位,并用u赋值;如果u超过n位,则顶端被截除如:bitset<5>b0(5);则"b0"为"00101&

【原根】【动态规划】【bitset】2017四川省赛 K.2017 Revenge

题意: 给你n(不超过200w)个数,和一个数r,问你有多少种方案,使得你取出某个子集,能够让它们的乘积 mod 2017等于r. 2017有5这个原根,可以使用离散对数(指标)的思想把乘法转化成加法,然后就可以用bitset优化dp了. 裸的dp方程是f(i,j)=f(i-1,j)+f(i-1,(j-I(a(i)))%2016),第一维可以滚动.I(i)规定为i的指标,但是我们这里不像<数论概论>那本书上把I(1)规定为2016,而当成0,比较方便. #include<cstdio&g

bzoj3687简单题(dp+bitset优化)

3687: 简单题 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 861  Solved: 399[Submit][Status][Discuss] Description 小呆开始研究集合论了,他提出了关于一个数集四个问题:1.子集的异或和的算术和.2.子集的异或和的异或和.3.子集的算术和的算术和.4.子集的算术和的异或和.    目前为止,小呆已经解决了前三个问题,还剩下最后一个问题还没有解决,他决定把这个问题交给你,未来的集训队队员来实现

bitset用法

转自:http://www.cppblog.com/ylfeng/archive/2010/03/26/110592.html 声明#include <bitset>using std::bitset; bitset的定义和初始化bitset<32> bitvec; //32位,全为0. 给出的长度值必须是常量表达式.正如这里给出的,长度值必须定义为整型字面值常量或是已用常量值初始化的整数类型的const对象. 这条语句把bitvec定义为含有32个位的bitset对象.和vect