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
code:
#include <stdio.h>
#include <string.h>
int main()
{
int a[200010], b[200010];
int n, m, i, x;
while(~scanf("%d%d", &n, &m))
{
memset(b, 0, sizeof(a));
for(i = 0;i<n;i++)
{
scanf("%d", &a[i]);
}
for(i = 0;i<m;i++)
{
scanf("%d", &x);
b[x+100000] = 1;
}
for(i = 0;i<n;i++)
{
printf("%d", b[a[i]+100000]);
}
printf("\n");
}
}
本篇介绍了一个算法问题,即如何通过给定的集合A及其子集B,使用二进制字符串来表示子集B。具体实现包括读取输入数据、标记子集元素并输出对应的01字符串。

被折叠的 条评论
为什么被折叠?



