您的位置:首页 > 其它

离散题目10

2017-05-24 20:17 183 查看
离散题目10

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic

Problem Description

给定一个数学函数F和两个集合A,B,写一个程序来确定函数是满射。 如果每个可能的像至少有一个变量映射其上(即像集合B中的每个元素在A中都有一个或一个以上的原像),或者说值域任何元素都有至少有一个变量与之对应,那这个映射就叫做满射。

Input

多组输入直到文件结束,对于每组输入,第一行先输入一个n(A集合里的元素个数),m(B集合里的元素个数),k(F数学函数关系的条数)。

0 < n,m < 10000, 0 < k < n;

第二行输入有n个元素,分别为a1到an;

第三行输入有m个元素,分别为b1到bn;

接下来输入有k行,分别为集合A到B的关系

Output

(一组答案占一行)

当满足满射关系时输出Yes。

不满足关系时输出No。

Example Input

5 3 5

1 3 5 7 8

2 5 6

1 2

3 6

5 5

7 2

8 6

Example Output

Yes

Think:判断是不是集合B当中的元素都有A集合中的元素与之对应

#include <stdio.h>
#include <string.h>
int a,b,c,d,e[10010],f[10010],s[10010];
int main(){
int n,m,x;
while(~scanf("%d%d%d",&n,&m,&x)){
memset(e,0,sizeof(e));
memset(f,0,sizeof(f));
memset(s,0,sizeof(s));
for (int i=0;i<n;i++){
scanf("%d",&a);
e[a]++;
}
for (int i=0;i<m;i++){
scanf("%d",&b);
f[b]++;
}
int count=0;
for (int i=0;i<x;i++){
scanf("%d%d",&c,&d);
if (e[c]>0&&f[d]>0){
s[d]++;
if (s[d]==1){
count++;
}
}
}
if (count==m){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: