离散题目8

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
code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, t;
    set<int> q, r;
    string str, buf;
    while(~scanf("%d", &n))
    {
        getline(cin, str);
        getline(cin, str);
        stringstream ss(str);
        while(ss >> buf)
        {
            sscanf(buf.c_str(), "%d", &t);
            q.insert(t);
        }
        getline(cin, str);
        stringstream cc(str);
        while(cc>>buf)
        {
            sscanf(buf.c_str(), "%d", &t);
            r.insert(t);
        }
        for(i = 1;i<=n;i++)
        {
            if(q.count(i)&&r.count(i)) printf("1");
            else printf("0");
        }
        printf("\n");
        for(i = 1;i<=n;i++)
        {
            if(q.count(i)||r.count(i)) printf("1");
            else printf("0");
        }
        printf("\n");
        r.clear();
        q.clear();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值