POJ2443 Set Operation —— bitset
题目链接:https://vjudge.net/problem/POJ-2443
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 3554 | Accepted: 1477 |
Description
Input
Output
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
Source
题意:
给出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的更多相关文章
- 【bitset】poj2443 Set Operation
模板题.S[i][j]表示i是否存在于第j个集合里.妈蛋poj差点打成poi(波兰无关)是不是没救了. #include<cstdio> #include<bitset> us ...
- 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 ...
- [POJ2443]Set Operation(bitset)
传送门 题意:给出n个集合(n<=1000),每个集合中最多有10000个数,每个数的范围为1~10000,给出q次询问(q<=200000),每次给出两个数u,v判断是否有一个集合中同时 ...
- [POJ 2443] Set Operation (bitset)
题目链接:http://poj.org/problem?id=2443 题目大意:给你N个集合,每个集合里有若干个数.M个查询,每个查询有a,b两个数.问是否存在一个集合同时包含a,b这两个数.若存在 ...
- poj2443Set Operation (bitset)
Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set ...
- poj2443(简单的状态压缩)
POJ2443 Set Operation Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2679 Accepted: ...
- Bitset小结 (POJ2443 & HDU4920)
学了下bitset用法,从网上找的一些bitset用法,并从中调出一些常用的用法. 构造函数bitset<n> b; b有n位,每位都为0.参数n可以为一个表达式.如bitset<5 ...
- POJ244Set Operation(bitset用法)
Bryce1010模板 /* 题意:给出n个集合(n<=1000),每个集合中最多有10000个数, 每个数的范围为1~10000,给出q次询问(q<=200000), 每次给出两个数u, ...
- 【Bitset】重识
---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...
随机推荐
- StringUtils和IOUtils工具包的使用
加载apache的工具类 <dependency> <groupId>commons-lang</groupId> <artifactId>common ...
- linux中read用法
read在while中的经常用法: root@ubuntu:/var/lib/logrotate :: # cat /etc/cron.daily/logrotate #!/bin/sh # Clea ...
- C++ 关于类与对象在虚函数表上唯一性问题 浅析
[摘要] 非常多教材上都有介绍到虚指针.虚函数与虚函数表.有的说类对象共享一个虚函数表,有的说,一个类对象拥有一个虚函数表.还有的说,不管用户声明了多少个类对象,可是,这个VTABLE虚函数表仅仅有一 ...
- 【Excle数据透透视表】如何删除数据透视表
选中区域A4:C17,在键盘上按DELETE键删除,结果提示: 那么如何删除呢? 解决方案 选中整个数透视表,再删除 具体操作: 选中整个数据透视表→DELETE 注意:删除之后,源数据不会受到影响
- View的滚动原理简单解析
一直对View的滚动了解的不深,说明确了吧也能说出个所以然来,所以我就花了点时间做了一个小小的总结,言归正传,view的滑动分为下面三种: 1)View本身不滚动,指滚动View的内容,这也是View ...
- ORCAD中的一些操作小技巧
1.ORCAD中改变元器件和文本字体颜色的命令: 打开在 View -> Toolbar -> Command Window.然后圈选文字(可复选),然后到 Command Window ...
- 1. WPF学习之概述
<深入浅出WPF> 前言: C#专业的朋友推荐的WPF入门书籍<深入浅出WPF>,没学过的朋友从今天开始和我一起开启WPF学习之旅吧! 什么是WPF? WPF 是windows ...
- hashCode与equals的作用与区别及应当注意的细节
最近去面试了几家公司,被问到hashCode的作用,虽然回答出来了,但是自己还是对hashCode和equals的作用一知半解的,所以决定把它们研究一下. 以前写程序一直没有注意hashCode的作用 ...
- java 表示当前时间的第二天的几点
Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_YEAR, 1); ...
- 查看SELinux状态并关闭SELinux
SELinux(Security-Enhanced Linux)是Linux上最杰出的新安全子系统.在linux内核级别上提供了一个灵活的强制访问控制系统(MAC),这个强制访问控制系统是建立在自由访 ...