标签:++ clu cst return org ace amp include logs
题意:给出n个集合(n<=1000),每个集合中最多有10000个数,每个数的范围为1~10000,给出q次询问(q<=200000),每次给出两个数u,v判断是否有一个集合中同时含有u,v两个数
枚举每一个集合,看看是否同时又u和v,显然超时
用bitset维护每一个数所在集合,求解的时候直接即可u & v
#include <cstdio> #include <bitset> using namespace std; int n, m; bitset <1001> t, s[10001]; int main() { int i, j, x, y; while(~scanf("%d", &n)) { for(i = 0; i <= 10000; i++) s[i].reset(); for(i = 1; i <= n; i++) { scanf("%d", &m); for(j = 1; j <= m; j++) { scanf("%d", &x); s[x][i] = 1; } } scanf("%d", &m); for(i = 1; i <= m; i++) { scanf("%d %d", &x, &y); t = s[x] & s[y]; if(t.count()) puts("Yes"); else puts("No"); } } return 0; }
[POJ2443]Set Operation(bitset)
标签:++ clu cst return org ace amp include logs
原文地址:http://www.cnblogs.com/zhenghaotian/p/7496169.html