POJ2443 Set Operation(Bitset)

 

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

 學習一下Bitset

 

AC代碼:

#include <bitset>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 10000 + 5;
bitset<maxn> a[maxn];
int N, Q;
int x, y;
int m, p;
int main() {
        //清零
        //for(int i = 0; i < maxn; i++) a[i].reset();
        scanf("%d",&N);
        for(int i = 1; i <= N; i++) {

            scanf("%d",&m);
            for(int j = 1; j <= m; j++) {
                scanf("%d",&p);
                a[p].set(i);
            }
        }
        scanf("%d",&Q);
        while(Q--) {
            scanf("%d%d",&x,&y);
            int flag = 0;
            if((a[x] & a[y]).any()) flag = 1;
            if(flag) printf("Yes\n");
            else printf("No\n");
        }

    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章