POJ 2443 - Set Operation

注意变换思维,然后就是水题。(如果卡时还可以进一步二分优化。)


#include <stdio.h>

long existed[10000][32];

int main(void)
{
int N;
// freopen("poj2443.txt", "r", stdin);
scanf("%d", &N);
int i, j;
for(i=0; i<N; ++i) {
int C, k;
scanf("%d", &C);
for(j=0; j<C; ++j) {
scanf("%d", &k); --k;
existed[k][i >> 5] |= 1 << (i&31);
}
}
int Q;
for(scanf("%d", &Q); Q; --Q) {
int p,q;
scanf("%d%d", &p, &q); --p, --q;
for(i=0; i<32; ++i)
if (existed[p][i] & existed[q][i])
break;
if (i < 32) printf("Yes\n");
else printf("No\n");
}
return 0;
}










2443 Accepted 1636K 1641MS GCC 548B 2014-05-01 02:23:30

POJ 2443 - Set Operation

时间: 2024-08-13 21:59:55

POJ 2443 - Set Operation的相关文章

[POJ 2443] Set Operation (bitset)

题目链接:http://poj.org/problem?id=2443 题目大意:给你N个集合,每个集合里有若干个数.M个查询,每个查询有a,b两个数.问是否存在一个集合同时包含a,b这两个数.若存在则输出Yes,否则为No. 康神竟然一下子就想出来了.. 思路:统计每个数在哪个集合出现过,用bitset记录下来.然后对于a,b,则把两个bitset取与. 如果得到空集就是No,否则就是Yes. 1 #include <cstdio> 2 #include <bitset> 3 #

poj 2443

Set Operation Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2961   Accepted: 1192 Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't entirely the same as the "set" defi

【搭楼】做题记录

以后做了题还是在这里写一下,觉得好的再去发题解(感觉无脑发题解意义不大) 也不一定是做了的题,看了没打但觉得不错的也可以发上来 (5.23-5.24 第三次月考被X得相当爽) 5.23 星期六 [贪心]Bzoj4027 HEOI2014 兔子与樱花 要是父亲合并儿子又合并就混乱了.然后发现,反正贡献都是一?能合并就在儿子处合并?贪心. [分块]Bzoj3343 教主的魔法 做之前知道了tag,于是很快就想到了算法.还没打过分块呢,于是先去膜拜了一下别人的代码.自己打出来后各种WA,太晚了没调出来

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(

POJ 3087 Shuffle&#39;m Up(模拟退火)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

POJ 3468 A Simple Problem with Integers

链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77302 Accepted: 23788 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two ki

poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83959   Accepted: 25989 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. Yo

POJ 2155 Matrix(二维树状数组,绝对具体)

Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1

POJ 3414 Pots(罐子)

p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 24.0000pt } span.10 { font-family: "Times New Rom