bitset

The Cow Doctor UVALive - 3524(使用bitset)枚举

匿名 (未验证) 提交于 2019-12-03 00:34:01
传送门 题意:判断一个集合是否已经由其他集合构成,也就是留下最小的子集 题解:使用bitset,设置两个bitset变量a,b,使用a记录每个药的集合,使用b记录可由其他药品构成的最终情况 //利用bitset来判断该集合是否已经有其他集合构成 #include<iostream> #include<cstdio> #include<bitset> using namespace std; const int maxn=305; bitset<maxn>a[maxn]; bitset<maxn>b[maxn]; int main() { int n,m,cnt,xu; while(scanf("%d%d",&n,&m)!=EOF&&(n||m)){ for(int i=0;i<m;i++){ a[i]=b[i]=0; } for(int i=0;i<m;i++){ scanf("%d",&cnt); while(cnt--){ scanf("%d",&xu); a[i].set(xu); } for(int j=0;j<i;j++){ if((a[i]&a[j])==a[i]){ b[j]|=a[i]; }else if((a[i]&a[j])==a[j]){ b[i]|=a[j]; } } } int cnt=0; for(int i=0;i<m;i++){ if(a[i]==b

EOJ3337 我认识你

匿名 (未验证) 提交于 2019-12-03 00:20:01
3337. 我认识你 DESCRIPTION STATISTICS DISCUSSION 2.0 seconds 256 megabytes 人与人之间的关系错综复杂,常常会出现一个叫作共同好友的东西。所以,贴心的 QQ 就提供了这样一个功能,可以显示你与某人(不一定是好友)有多少个共同好友。但是,当用户量逐渐增大,好友关系网不断复杂化,共同好友计算的效率就变得十分重要了。 你刚刚和腾讯公司签约,获得了共同好友计算的开发资格。 Input n , m ( 1 ≤ n ≤ 40 000 , 1 ≤ m ≤ 40 000 ) 1 n 。 m u , v ( 1 ≤ u , v ≤ n , u ≠ v ) u v u , v 。 q ( 1 ≤ q ≤ 40 000 ) q s , t ( 1 ≤ s , t ≤ n , s ≠ t ) ,表示询问的对象。 小数据规模说明: 20 % 1 ≤ n ≤ 10 , 1 ≤ q ≤ 200 。 40 % 1 ≤ n ≤ 1 000 。 Output 对于每组询问,输出这两个人有多少个共同好友。 Examples input 3 3 1 2 1 3 3 2 2 1 3 3 2 output 1 1 input 4 4 1 2 1 4 2 3 3 4 3 1 3 1 4 2 4 output 2 0 2 input 3 2 1 2 1 3 2 2

8.21

匿名 (未验证) 提交于 2019-12-03 00:13:02
bitset 二进制状态压缩 LYD P8 #include < bits / stdc ++. h > using namespace std ; bitset < 30 > a , b (( 1 << 30 )- 1 ), c ; int n , m , r ; char s [ 5 ]; int main (){ scanf ( "%d%d" ,& n ,& m ); for ( int i = 1 ; i <= n ; i ++){ scanf ( "%s%d" , s ,& r ); if ( s [ 0 ]== 'A' ) a &= r , b &= r ; if ( s [ 0 ]== 'O' ) a |= r , b |= r ; if ( s [ 0 ]== 'X' ) a ^= r , b ^= r ; } for ( int i = 0 ; i < 30 ;++ i ){ if ( a [ i ]|( b [ i ] && c . to_ulong ()< m )) c [ i ]= 1 ; } printf ( "%d" , c . to_ulong ()); } bitset用来存储二进制数位。像一个bool类型的数组一样,bitset每个元素只有0或1两个数值。 但是有空间优化――bitset中的一个元素一般只占1 bit。

Bitset in C++, about continuously add

為{幸葍}努か 提交于 2019-12-02 13:46:43
问题 I want to add 1 value to the bitset until it over flows, I am wondering how to do this, like: bitset<20> foo; (foo=00000 00000 00000 00000) how can we implement this function, continuously add one 00000 00000 00000 00000 00000 > 00000 00000 00000 00000 00001 > 00000 00000 00000 00000 >00010 > 00000 00000 00000 00000 000011 until it overflows? I am thinking about two ways; foo.to_ulong(); how to convert unsigned long back to bitset again? C++ documentation indicates it is possible, but in the

题解 P5594 【【XR-4】模拟赛】

余生颓废 提交于 2019-12-02 11:15:23
P5594 【【XR-4】模拟赛】 洛谷10月月赛 II & X Round 4 Div.2前两道签到题还是很简单的,基本上是半小时内一遍过两题 看看题解,这题STL做法有用set输出size的和vector+unique的,我在打二维数组代吗的时候突然发现可以用bitset代替 用二进制数记录每天每场比赛有无的情况(有的话就把那一位变成1),用bitset中的count输出二进制数1的个数即可 #include<cstdio> #include<bitset> using namespace std; int n,i,m,k,x; bitset<1001> a[1001]; int main(){ scanf("%d%d%d",&n,&m,&k); for (;n;n--){ for (i=1;i<=m;i++) scanf("%d",&x),a[x][i]=1; } for (i=1;i<=k;i++) printf("%d ",a[i].count()); } 来源: https://www.cnblogs.com/Randolph68706/p/11742855.html

DES算法与四种加密模式的代码实现(C++语言)

时光总嘲笑我的痴心妄想 提交于 2019-12-02 08:49:00
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/Love_Irelia97/article/details/102597577 本文主要是对《信息安全技术》的DES算法实验作业的一些总结,不会着重地介绍算法原理,而会在算法实现过程中给出自己的理解 (因为有些部分我也不知道正确与否,如有错误请指教)。 文章中出现的原理介绍和配图,均参考自其它博客,相关链接将在文中给出。 另外,文中的代码都是根据内容截取的,若想查看 完整代码 ,请参考 DES - github 一、DES算法简介(参考自 DES算法实例详解 ) DES(Data Encryption Standard)是一种用于电子数据加密的对称密钥块加密算法。 它以64bit一组的明文 (Input) 作为算法的输入,通过一系列复杂的操作,输出同样64bit长度的密文 (Output) 。DES 同样采用64位密钥 (Key) ,但由于每8bit中的最后1位用于奇偶校验,实际有效密钥长度为56bit ( Tips:输入的Key依然是64bit,只是在映射时不对每个字节最后1位进行处理,所以变为了56bit ) 。 DES 使用加密密钥定义变换过程,因此算法认为只有持有加密所用的密钥的用户才能解密密文

DES算法与四种加密模式的代码实现(C++语言)

人盡茶涼 提交于 2019-12-02 08:46:37
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/Love_Irelia97/article/details/102597577 本文主要是对《信息安全技术》的DES算法实验作业的一些总结,不会着重地介绍算法原理,而会在算法实现过程中给出自己的理解 (因为有些部分我也不知道正确与否,如有错误请指教)。 文章中出现的原理介绍和配图,均参考自其它博客,相关链接将在文中给出。 另外,文中的代码都是根据内容截取的,若想查看 完整代码 ,请参考 DES - github 一、DES算法简介(参考自 DES算法实例详解 ) DES(Data Encryption Standard)是一种用于电子数据加密的对称密钥块加密算法。 它以64bit一组的明文 (Input) 作为算法的输入,通过一系列复杂的操作,输出同样64bit长度的密文 (Output) 。DES 同样采用64位密钥 (Key) ,但由于每8bit中的最后1位用于奇偶校验,实际有效密钥长度为56bit ( Tips:输入的Key依然是64bit,只是在映射时不对每个字节最后1位进行处理,所以变为了56bit ) 。 DES 使用加密密钥定义变换过程,因此算法认为只有持有加密所用的密钥的用户才能解密密文

Bitset in C++, about continuously add

戏子无情 提交于 2019-12-02 07:17:45
I want to add 1 value to the bitset until it over flows, I am wondering how to do this, like: bitset<20> foo; (foo=00000 00000 00000 00000) how can we implement this function, continuously add one 00000 00000 00000 00000 00000 > 00000 00000 00000 00000 00001 > 00000 00000 00000 00000 >00010 > 00000 00000 00000 00000 000011 until it overflows? I am thinking about two ways; foo.to_ulong(); how to convert unsigned long back to bitset again? C++ documentation indicates it is possible, but in the library, I can only see bitset (unsigned long val), which is creating a new bitset 2. somehow bit

Bit Manipulation常用总结

大憨熊 提交于 2019-12-02 05:24:05
1.判断奇偶 奇偶数的特征:如果一个数是偶数,则对于其二进制来说,最低位肯定是0;如果一个数是奇数,则对于其二进制来说,最低位肯定是1,因为在二进制表示中,只有 会产生1 所以可以利用这一特征来判断奇偶数 if(num&1 == 0) { //偶数 } else { //奇数 } 2.消去一个数中的最低位 比如十进制数5(0101), 我们要消去其二进制中的最低位的1 则 操作是 (5&4) = (0101 & 0100) = 0100,从而将最低位处的1消除 典型应用:统计一个数的二进制表示中有多少个1 int hammingWeight(uint32_t n) { int count = 0; while(n) { count++; n &= (n-1); } return count; } 3.将二进制数进行翻转操作 可以用到C++中的bitset,它是类似于一个数组的结构,其内部元素只能是0或1,且每一位只占1bit bitset数组简介: bitset<8> bitset1; //构造长度为4的bitset数组,每一位默认为0 bitset<8> bitset2(12); //构造长度为8的数组,并用12的二进制去初始化 //也可以用字符串来进行构造 string s = "11000"; bitset<8> bitset3(s); //注

Trying to flip the order of bits in std::bitset

十年热恋 提交于 2019-12-02 04:18:52
问题 I'm working on a structure that uses std::bitset and it looks like this: Register.h #pragma once #include <bitset> #include <vector> // used for typedefs of int types namespace vpc { // virtual pc typedef std::int8_t i8; typedef std::int16_t i16; typedef std::int32_t i32; typedef std::int64_t i64; const unsigned int BYTE = 0x08; const unsigned int WORD = 0x10; const unsigned int DWORD = 0x20; const unsigned int QWORD = 0x40; typedef std::bitset<BYTE> Byte; typedef std::bitset<WORD> Word;