离散题目8
来源:互联网 发布:淘宝烟丝 编辑:程序博客网 时间:2024/05/20 05:09
离散题目8
Time Limit: 1000MS Memory Limit: 65536KB
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
think:
按照题目的描述,根据题意,写了好几遍,也改了好几遍,就是不明白为什么WA……
后来,问了一个同学(SJ)他只加了一行代码,就AC了……
终于明白了离散的后台数据有多坑……
由于数据是在windows系统下生成的,换行并不是轻易的换行就能完成的,据说是\r\n, 要用两个getchar();
(他是这样解释的,我不知道对不对……)
#include <bits/stdc++.h>using namespace std;int main(){ int n; while(cin>>n) { getchar(); getchar();//坑点 vector<int> a, b; vector<int>::iterator it, it1; int t; string ac, bc, buf; getline(cin, ac); getline(cin, bc); stringstream ss(ac); while(ss>>buf) { sscanf(buf.c_str(), "%d", &t); a.push_back(t); } stringstream cc(bc); while(cc>>buf) { sscanf(buf.c_str(), "%d", &t); b.push_back(t); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for(int i=1;i<=n;i++) { it = find(b.begin(), b.end(), i); it1 = find(a.begin(), a.end(), i); if((it!=b.end())) { if(it1!=a.end()) cout<<'1'; else cout<<'0'; } else cout<<'0'; } cout<<endl; for(int i=1;i<=n;i++) { it = find(b.begin(), b.end(), i); it1 = find(a.begin(), a.end(), i); if((it!=b.end())) { cout<<'1'; } else if(it1!=a.end()) { cout<<'1'; } else cout<<'0'; } cout<<endl; a.clear(); b.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
- AndroidStudio本地化配置gradle的buildToolsVersion和gradleBuildTools
- 轮播图--文字上下方向自动滑动
- 第4章C/C++语言基础 4.3~4.6
- swift3 保存json到桌面,从沙盒中读取json
- 4836: [Lydsy2017年4月月赛]二元运算
- 离散题目8
- Spring的自动装配
- Java多线程之内存可见性
- 10、Linux根文件系统的制作
- HDU 1241 Oil Deposits
- 算法导论 练习题 15.3-1
- 数据库设计(降龙十四招式)
- 分布式系统中的几种数据备份模式. 数据可靠性(基本,),数据一致性(脑裂问题,高可靠性容灾性),数据可用性(数据拆分,读写分离),系统扩展性.
- Linux查看文件夹inode数 和 文件数量过多无法ls问题解决