bitset骚操作

bitset的用途挺多的,是一个比较骚的常数优化

 

一.很多位数的二进制数

poj 2443

http://poj.org/problem?id=2443

 直接开个1万位的二进制数,求交就行了。

有关集合求并交的时候可以考虑biset优化

#include<bitset>
#include<cstdio> 
#define REP(i, a, b) for(register int i = (a); i < (b); i++)
#define _for(i, a, b) for(register int i = (a); i <= (b); i++)
using namespace std;

const int MAXN = 1e3 + 10;
const int MAXM = 1e4 + 10;
bitset<MAXN> s[MAXM];

int main()
{
    int n;
    scanf("%d", &n);
    
    _for(i, 1, n)
    {
        int m, x;
        scanf("%d", &m);
        _for(j, 1, m)
        {
            scanf("%d", &x);
            s[x][i] = 1;
        }
    }
    
    int q;
    scanf("%d", &q);
    
    while(q--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if((s[a] & s[b]).any()) puts("Yes");
        else puts("No");
    }
    
    return 0;
}

 

二.可以优化01背包中当前状态是否存在的问题,可以在原来的基础上除以32

见这篇博客

https://www.cnblogs.com/chinacwj/p/8371578.html

 

三.在统计类问题中用集合中的并优化常数

见这道题

https://blog.csdn.net/qq_37867156/article/details/82497948

转载于:https://www.cnblogs.com/sugewud/p/9892440.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值