离散题目8
来源:互联网 发布:通用数字滤波算法 编辑:程序博客网 时间:2024/05/29 23:47
离散题目8
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem 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
10
1 3 5 7 8
2 5 6
Example Output
0000100000
1110111100
Hint
注意题目和以前的介绍貌似有一点不同,题目要求第一行为集合U的指标参数N。本题的测试数据在输入一个n之后有大量的空格。造成接下来的数据读取有误。
错误的代码
#include<bits/stdc++.h>using namespace std;int a[100],b[100];int main(){ int n; string in1,in2; stringstream in; while(cin>>n)//不会读取之后的空格 { int x; getchar(); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); getline(cin,in1); getline(cin,in2); in.clear(); in.str(in1); while(true) { in>>x; if(in.fail()) { break; } a[x]++; } in.clear(); in.str(in2); while(true) { in>>x; if(in.fail()) { break; } b[x]++; } for(int i = 1;i<=n;i++) { if(a[i]&&b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; for(int i = 1;i<=n;i++) { if(a[i]||b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; }}/***************************************************User name: rj160206武志祥Result: Wrong AnswerTake time: 0msTake Memory: 208KBSubmit time: 2017-06-20 12:13:20****************************************************/
#include<bits/stdc++.h>using namespace std;int a[100],b[100];int main(){ int n; string in1,in2; stringstream in; string com; while(getline(cin,com))//读取整行的内容包括空格 { in.clear(); in.str(com); in>>n; int x; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); getline(cin,in1); getline(cin,in2); in.clear(); in.str(in1); while(true) { in>>x; if(in.fail()) { break; } a[x]++; } in.clear(); in.str(in2); while(true) { in>>x; if(in.fail()) { break; } b[x]++; } for(int i = 1;i<=n;i++) { if(a[i]&&b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; for(int i = 1;i<=n;i++) { if(a[i]||b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; }}/***************************************************User name: rj160206武志祥Result: AcceptedTake time: 0msTake Memory: 208KBSubmit time: 2017-06-20 12:16:53****************************************************/
#include<bits/stdc++.h>using namespace std;int a[100],b[100];int main(){ int n; string in1,in2; stringstream in; string com; while(getline(cin,com)) { in.clear(); in.str(com); in>>n; int x; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); getline(cin,in1); getline(cin,in2); in.clear(); in.str(in1); while(true) { in>>x; if(in.fail()) { break; } a[x]++; } in.clear(); in.str(in2); while(true) { in>>x; if(in.fail()) { break; } b[x]++; } for(int i = 1;i<=n;i++) { if(a[i]&&b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; for(int i = 1;i<=n;i++) { if(a[i]||b[i]) { printf("1"); } else { printf("0"); } } cout<<endl; }}
阅读全文
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 C++>:Item25:考虑写出一个不抛出异常的swap函数
- Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
- 微信小程序实现list跳转带值传递
- 复制构造函数 与 赋值函数 的区别
- 如何使用mysql命令行 ?
- 离散题目8
- 阻塞队列Queue/Deque/condition
- 湖南省第七届大学生计算机程序设计竞赛
- UNITY MAC破解失败解决办法-应用UNITY打不开
- Android 优化简要总结
- Python-多线程
- 将Office(如:Word、Excel、PPT 等)文件转PDF(通过OpenOffice实现)
- js浮点数运算保留两位小数点
- 浅谈对于前端库的理解