离散题目7

来源:互联网 发布:安捷伦数据采集器软件 编辑:程序博客网 时间:2024/05/29 21:17

离散题目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 51 2 3 4 5 6 7 8 9 101 3 5 7 8

Example Output

1010101100

Hint

Author

MeiK


此题相对来说很简单,只需要看出01的特点即可,在集合中有元素的位置即为1 无元素即为0

代码用时208ms,平台sdutoj

#include <iostream>#include<bits/stdc++.h>using namespace std;int main(){    int m,n;    while(cin>>m>>n)    {        int a[100000] = {0};        int b[100000] = {0};        int c[100000] = {0};        for(int i = 0; i < m; i++)        {            cin>>a[i];        }        for(int i = 0; i < n; i++)        {            cin>>b[i];        }        int j = 0;        for(int i = 0; i < n; i++)            for(; j < m; j++)            {                if(a[j] == b[i])                {                    c[j]++;                    break;                }            }        for(int i = 0; i < m; i++)        {            cout<<c[i];        }        cout<<endl;    }    return 0;}



以下为校友BlessingXRY 桶排序——负坐标方法

用时 112ms 平台sdutoj


#include <iostream>#include <algorithm>#include <cstdio>using namespace std;int main(){    int n, m, i, v, x[100004], vid[200004];    while(scanf("%d %d", &n, &m) != EOF)    {        for(i = 0; i < n; i++)        {            scanf("%d", &x[i]);            vid[x[i]+100000] = 0;        }        for(i = 0; i < m; i++)        {            scanf("%d", &v);            vid[v+100000] = 1;        }        for(i = 0; i < n; i++)        {            printf("%d", vid[x[i]+100000]);        }        printf("\n");    }    return 0;}


原创粉丝点击