离散题目8
来源:互联网 发布:刷机软件 编辑:程序博客网 时间:2024/05/20 01:35
离散题目8
Time Limit: 1000MS Memory Limit: 65536KBSubmit StatisticProblem Description
现有一个全集U,U={ x | x>=1 && x<=N } 。
对于U的任意子集A,现在定义一种位集(bitset)Abit用来描述U的子集A: 该位集由1,0组成,长度为N,对于集合A中的任意元素x,集合Abit 在第x位且仅在第x位有对应的1存在,其余位置为0。
例如: 对于全集U,其对应的描述位集Ubit = { 111...1 } (N个1); 对于集合A = { 1,2,3,N },其对应的描述位集Abit = { 1110...01 };
Input
多组输入,每组输入包括三行,第一行为集合U的指标参数N( 0< N < = 64 ),第二行为集合A的元素,第三行为集合B的元素,元素之间用空格分割,具体参考示例输入。
Output
每组输入对应两行输出,第一行为A、B的交集的描述位集。第二行为A、B的并集的描述位集。
Example Input
101 3 5 7 82 5 6
Example Output
00001000001110111100
代码:#include <bits/stdc++.h>using namespace std;int main(){int n;string str, buf;set<int> s, t;while(cin>>n){int i, num;getline(cin, str);getline(cin, str);stringstream ss(str);while(ss>>buf){sscanf(buf.c_str(), "%d", &num);s.insert(num);}getline(cin, str);stringstream cc(str);while(cc>>buf){sscanf(buf.c_str(), "%d", &num);t.insert(num);}for(i = 0; i < n; i++){if(s.count(i+1)&&t.count(i+1))cout<<"1";else cout<<"0";}cout<<endl;for(i = 0; i < n; i++){if(s.count(i+1)||t.count(i+1))cout<<"1";else cout<<"0";}cout<<endl;s.clear();t.clear();}return 0;}
现有一个全集U,U={ x | x>=1 && x<=N } 。
对于U的任意子集A,现在定义一种位集(bitset)Abit用来描述U的子集A: 该位集由1,0组成,长度为N,对于集合A中的任意元素x,集合Abit 在第x位且仅在第x位有对应的1存在,其余位置为0。
例如: 对于全集U,其对应的描述位集Ubit = { 111...1 } (N个1); 对于集合A = { 1,2,3,N },其对应的描述位集Abit = { 1110...01 };
多组输入,每组输入包括三行,第一行为集合U的指标参数N( 0< N < = 64 ),第二行为集合A的元素,第三行为集合B的元素,元素之间用空格分割,具体参考示例输入。
每组输入对应两行输出,第一行为A、B的交集的描述位集。第二行为A、B的并集的描述位集。
101 3 5 7 82 5 6
Example Output
00001000001110111100
代码:#include <bits/stdc++.h>using namespace std;int main(){int n;string str, buf;set<int> s, t;while(cin>>n){int i, num;getline(cin, str);getline(cin, str);stringstream ss(str);while(ss>>buf){sscanf(buf.c_str(), "%d", &num);s.insert(num);}getline(cin, str);stringstream cc(str);while(cc>>buf){sscanf(buf.c_str(), "%d", &num);t.insert(num);}for(i = 0; i < n; i++){if(s.count(i+1)&&t.count(i+1))cout<<"1";else cout<<"0";}cout<<endl;for(i = 0; i < n; i++){if(s.count(i+1)||t.count(i+1))cout<<"1";else cout<<"0";}cout<<endl;s.clear();t.clear();}return 0;}
阅读全文
0 0
- 离散题目8
- 离散题目8
- 离散题目8
- 离散题目8
- 离散题目8
- 离散题目8
- sdut-离散题目8
- 离散题目8
- SDUT 3802 离散题目8
- 离散题目3
- 离散题目7
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- 离散题目12
- 离散题目15
- 3799-->离散题目5
- 3800-->离散题目6
- Effective Android:app优化 ------ 内存管理、内存泄漏、冷启动
- IO流中的重要方法
- jeesite学习笔记(一) 项目框架
- POJ 2186 Popular Cows(强连通分量模板题)
- 1187: 分糖果
- 离散题目8
- oracle分区表split
- C语言学习笔记-数组-郝斌老师讲解
- SpringBoot java程序打包
- RandomAccess接口
- Tomcat配置虚拟主机
- Spring_SSH整合之_架构的历史(三层架构整合JSP+MySQL+JavaBean)_2
- MySQL安装图解
- ArrayList源码解析(三)