【bitset】POJ2443 Set Operation

来源:互联网 发布:中国的未来 知乎 编辑:程序博客网 时间:2024/05/22 00:06

题面在这里

参考博客: C++ bitset使用教程
bitset最基础的练习题

示例程序:

#include<cstdio>#include<bitset>using namespace std;#define nc getcharint n,q;bitset<1002> S[10002];inline int red(){    int res=0,f=1;char ch=nc();    while (ch<'0'||'9'<ch) {if (ch=='-') f=-f;ch=nc();}    while ('0'<=ch&&ch<='9') res=res*10+ch-48,ch=nc();    return res*f;}int main(){    n=red();    for (int i=1;i<=n;i++)     for (int j=1,k=red();j<=k;j++)      S[red()].set(i);    q=red();    while (q--){        int i=red(),j=red();        if ((S[i]&S[j]).any()) printf("Yes\n");else printf("No\n");    }    return 0;}
原创粉丝点击