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】重识
---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...
随机推荐
- winform中tabControl的标题隐藏
方法一: Apperarance 属性:Faltbuttons SizeMode属性:Fixed 各个TabPage的Text :空 ItemSize : Width=0;Height=1; //He ...
- 如何选择Haproxy和Nginx
对于做软负载,我们都知道主流的方案有LVS.Haproxy.Nginx!那么对于Haproxy和Nginx,我们如何选择呢?回答这个问题之前,我根据个人使用经验来讲下它们的特点! Haproxy特点 ...
- iOS 应用内跳转到系统设置
在iOS5下面版本号使用下面方法:[IOS5.1+之后不能使用此方法.iOS8的跳转方法已找到见下方,iOS7的正在摸索,欢迎大家给出观点意见] 通过URL Scheme的方式打开内置的Setting ...
- kohana nginx的配置
kohana nginx的配置 location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php? kohana_uri=/$1 ...
- Reverse Linked List II -- 翻转部分链表
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given1->2 ...
- oracle恢复已经删除的数据
insert into tablerestore select * from tablerestore as of timestamp to_Date('2014-8-8 15:00:00','yyy ...
- 李振杰:火狐Mozilla被黑事件的启发
火狐浏览器开发商Mozilla近日宣布,因为数据库存在漏洞.Mozilla开发者的数万个电子邮件地址和加密password或遭到黑客窃取. 好多有为青年们往往刚刚获得了一个小成功,便開始沾沾自喜,自命 ...
- Array容易被忽略的join
var lists, items = '', i; lists = [{ Fruits:'苹果' },{ Fruits:'香蕉' },{ Fruits:'菠萝' }]; /*items += '< ...
- MongoDB水平分片集群(转)
为何需要水平分片 1 减少单机请求数,将单机负载,提高总负载 2 减少单机的存储空间,提高总存空间. 下图一目了然: mongodb sharding 服务器架构 简单注解: 1 mongos 路由进 ...
- OpenCV 中的三大数据类型( 概述 )
前言 OpenCV 提供了许多封装好了的类型,而其中,以三大类型最为核心.本文将大致介绍这三大类型. CvArr:不确定数组 它可以被视为一个抽象基类,后面的两大类型都继承此类型并扩展.只要某个函数的 ...