离散题目7

来源:互联网 发布:python 99乘法表思路 编辑:程序博客网 时间:2024/05/29 23:46

离散题目7
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

DaYu在新的学习开始学习新的数学知识,一天DaYu学习集合的时候遇到一个问题,他有一个集合A和A的子集B,他想用一个二进制串表示集合B。
Input

多组输入,每组的第一行有两个数n,m,(0< m < n < 10^5).
第二行输入n个数表示集合A,第三行输入m个数表示集合B,|data_i|< 10^5
Output

输出一个01字符串表示集合B
Example Input

10 5
1 2 3 4 5 6 7 8 9 10
1 3 5 7 8
Example Output

1010101100
Hint

Author

#include<bits/stdc++.h>using namespace std;int a[100100],b[100100];int ser(int b[],int low,int high,int key){    if(low<=high)    {        int mid = (low+high)/2;        if(b[mid]>key)        {            return ser(b,low,mid-1,key);        }        else if(b[mid]<key)        {            return ser(b,mid+1,high,key);        }        else        {            return 1;        }    }    else    {        return 0;    }}int main(){    int n,m;    while(cin>>n>>m)    {        for(int i =0;i<n;i++)        {            scanf("%d",&a[i]);        }        for(int i = 0;i<m;i++)        {            scanf("%d",&b[i]);        }        sort(b,b+m);        for(int i = 0;i<n;i++)        {            printf("%d",ser(b,0,m-1,a[i]));        }        cout<<endl;    }}
原创粉丝点击