题目链接:https://vjudge.net/problem/POJ-2443

Set Operation
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 3554   Accepted: 1477

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" defined in mathematics, and a set may contain two same element). Every element in a set is represented by a positive number from 1 to 10000. Now there are some queries need to answer. A query is to determine whether two given elements i and j belong to at least one set at the same time. In another word, you should determine if there exist a number k (1 <= k <= N) such that element i belongs to S(k) and element j also belong to S(k).

Input

First line of input contains an integer N (1 <= N <= 1000), which represents the amount of sets. Then follow N lines. Each starts with a number C(i) (1 <= C(i) <= 10000), and then C(i) numbers, which are separated with a space, follow to give the element in the set (these C(i) numbers needn't be different from each other). The N + 2 line contains a number Q (1 <= Q <= 200000), representing the number of queries. Then follow Q lines. Each contains a pair of number i and j (1 <= i, j <= 10000, and i may equal to j), which describe the elements need to be answer.

Output

For each query, in a single line, if there exist such a number k, print "Yes"; otherwise print "No".

Sample Input

3
3 1 2 3
3 1 2 5
1 10
4
1 3
1 5
3 5
1 10

Sample Output

Yes
Yes
No
No

Hint

The input may be large, and the I/O functions (cin/cout) of C++ language may be a little too slow for this problem.

Source

POJ Monthly,Minkerui

题意:

给出n个集合,每个集合有若干个数。有m个询问,问x、y是否存在于同一个集合中。

题解:

C++ bitset的应用。

具体介绍:https://blog.csdn.net/qll125596718/article/details/6901935

成员函数 函数功能
bs.any() 是否存在值为1的二进制位
bs.none() 是否不存在值为1的二进制位
或者说是否全部位为0
bs.size() 位长,也即是非模板参数值
bs.count() 值为1的个数
bs.test(pos) 测试pos处的二进制位是否为1
与0做或运算
bs.set() 全部位置1
bs.set(pos) pos位处的二进制位置1
与1做或运算
bs.reset() 全部位置0
bs.reset(pos) pos位处的二进制位置0
与0做或运算
bs.flip() 全部位逐位取反
bs.flip(pos) pos处的二进制位取反
bs.to_ulong() 将二进制转换为unsigned long输出
bs.to_string() 将二进制转换为字符串输出
~bs 按位取反
效果等效为bs.flip()
os << b 将二进制位输出到os流
小值在右,大值在左

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#include <bitset> //bitset头文件
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e5+; bitset<>a[];
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
for(int i = ; i<; i++)
a[i].reset();
for(int i = ; i<=n; i++)
{
int m, x;
scanf("%d", &m);
while(m--)
{
scanf("%d", &x);
a[x][i] = ;
}
} int m, x, y;
scanf("%d", &m);
while(m--)
{
scanf("%d%d", &x,&y);
if((a[x]&a[y]).count()) puts("Yes");
else puts("No");
}
}
}

POJ2443 Set Operation —— bitset的更多相关文章

  1. 【bitset】poj2443 Set Operation

    模板题.S[i][j]表示i是否存在于第j个集合里.妈蛋poj差点打成poi(波兰无关)是不是没救了. #include<cstdio> #include<bitset> us ...

  2. POJ2443 Set Operation (基础bitset应用,求交集)

    You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't ...

  3. [POJ2443]Set Operation(bitset)

    传送门 题意:给出n个集合(n<=1000),每个集合中最多有10000个数,每个数的范围为1~10000,给出q次询问(q<=200000),每次给出两个数u,v判断是否有一个集合中同时 ...

  4. [POJ 2443] Set Operation (bitset)

    题目链接:http://poj.org/problem?id=2443 题目大意:给你N个集合,每个集合里有若干个数.M个查询,每个查询有a,b两个数.问是否存在一个集合同时包含a,b这两个数.若存在 ...

  5. poj2443Set Operation (bitset)

    Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set ...

  6. poj2443(简单的状态压缩)

    POJ2443 Set Operation Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2679   Accepted:  ...

  7. Bitset小结 (POJ2443 & HDU4920)

    学了下bitset用法,从网上找的一些bitset用法,并从中调出一些常用的用法. 构造函数bitset<n> b; b有n位,每位都为0.参数n可以为一个表达式.如bitset<5 ...

  8. POJ244Set Operation(bitset用法)

    Bryce1010模板 /* 题意:给出n个集合(n<=1000),每个集合中最多有10000个数, 每个数的范围为1~10000,给出q次询问(q<=200000), 每次给出两个数u, ...

  9. 【Bitset】重识

    ---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...

随机推荐

  1. SQL must not be null(低级错误)

    提醒一下: 数据库数据源配置出错,也会发生这种低级错误的.

  2. Eclipse Memory Analyzer安装

    转载:http://www.jianshu.com/p/3b3c3a914724 1.下载地址:Eclipse Memory Analyzer Open Source Project   2.点击进入 ...

  3. 转载:JAVA中获取项目文件路径

    本文转载自:http://blog.163.com/michaelgaoit%40126/blog/static/11389538620103711613620/ web 上运行 1:this.get ...

  4. linux 文件删除恢复extundelete

    首先要把删除文件所有磁盘分区卸载掉 然后安装yum install -y extundelete *2fs* extundelete /dev/sdb1 --inode #查看sdb1分区下删除的文件 ...

  5. &和|不等同于&&或||

    &:位与 |:位或 &&:与 ||:或 当C编译器遇到这些符号时,会怎么样了? 当一个&或| 对位进行运算. 当二个&&或||对它进行与或运算. 千万不 ...

  6. eletron 播放rtmp flash 播放器问题

    1 安装 flash https://www.flash.cn/ 2 man.js 配置 参考 https://newsn.net/say/electron-flash-win.html 3 播放器 ...

  7. Mjpg_Streamer 的移植

    1. 移植mjpg-streamer a.1 移植libjpeg tar zxf libjpeg-turbo-1.2.1.tar.gz cd libjpeg-turbo-1.2.1 ./configu ...

  8. Spring学习十三----------Spring AOP的基本概念

    © 版权声明:本文为博主原创文章,转载请注明出处 什么是AOP -面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术 -主要的功能是:日志记录.性能统计.安全控制.事务处理. ...

  9. 《C专家编程》数组和指针并不同--多维数组

    <C专家编程>数组和指针并不同 标签(空格分隔): 程序设计论著笔记 1. 背景理解 1.1 区分定义与声明 p83 声明相当于普通声明:它所说明的并不是自身,而是描写叙述其它地方创建的对 ...

  10. Spring Security实现短信验证码登录

    Spring Security默认的一个实现是使用用户名密码登录,当初我们在开始做项目时,也是先使用这种登录方式,并没有多考虑其他的登录方式.而后面需求越来越多,我们需要支持短信验证码登录了,这时候再 ...