Set Operation POJ-2443

题目:bitset专属题

题解:稍微思考下,直接的做法枚举集合,空间开销太大,时间也会T。所以~~~~用bitset吧,超强大!!!

#pragma warning(disable:4996)
#include<bitset>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long

#define lson root<<1
#define rson root<<1|1
#define mid (l+r)>>1

#define mem(arr, in) memset(arr, in, sizeof(arr))
using namespace std;

const int maxn = 10004;

int n, m, q;
bitset<10005> tp, bit[10005];

int main()
{
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i <= 10000; i++) bit[i].reset();
        for (int i = 1; i <= n; i++) {
            scanf("%d", &m);
            for (int j = 1; j <= m; j++) {
                int x;
                scanf("%d", &x);
                bit[x][i] = 1;
            }
        }
        scanf("%d", &q);
        for (int i = 1; i <= q; i++) {
            int u, v;
            scanf("%d %d", &u, &v);
            tp = bit[u] & bit[v];
            if (tp.count() != 0) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}

 

posted @ 2018-05-31 18:07  天之道,利而不害  阅读(151)  评论(0编辑  收藏  举报