SDUT 3805 离散题目11
来源:互联网 发布:秋冬季男装 知乎 编辑:程序博客网 时间:2024/06/06 04:47
Problem Description
给定一个数学函数写一个程序来确定该函数是否是双射的
Input
多组输入。 第一行输入三个整数n,m,k,分别表示集合a中的元素个数,集合b中的元素个数,集合a到b的映射个数。 第二行输入n个数,代表集合a中的元素。 第三行输入m个数,代表集合b中的元素。接下来k行,每行两个数,代表集合a中的元素x和x在集合b中的像y。
Output
每组数据输出一行,若F为a到b的双射,输出”YES”, 否则输出”NO”。
Example Input
5 5 5
1 2 3 7 8
2 5 6 9 0
1 9
3 2
2 6
7 0
8 5
Example Output
YES
Hint
保证集合a中元素无重复,集合b中元素无重复,映射关系无重复(如:{,})
1<=n,m,k<=1000
1<=a[i], b[i]<=10000
x∈a, y∈b
代码:
#include<bits/stdc++.h>using namespace std;int main(){ int n, m, k, i, j, num; set<int> a, b; while(~scanf("%d %d %d", &n, &m, &k)) { int flag = 0; if(n != m || n != k || m != k) flag = 1;//无法满足双射 for(i = 0; i < n; i++)//集合a { scanf("%d", &num); a.insert(num); } for(j = 0; j < m; j++)//集合b { scanf("%d", &num); b.insert(num); } int x, y; while(k--) { scanf("%d %d", &x, &y); if(a.count(x) && b.count(y))//元素都在集合里面,删除掉 { a.erase(x); b.erase(y); } else flag = 1;//不满足双射 } if(flag) printf("NO\n"); else printf("YES\n"); a.clear(), b.clear(); }}
阅读全文
0 0
- SDUT 3805 离散题目11
- sdut离散题目11
- sdut-离散题目11
- sdut离散题目13
- sdut离散题目14
- SDUT-离散题目13
- SDUT-离散题目7
- SDUT离散题目4
- sdut-离散题目3
- sdut- 离散题目4
- sdut-离散题目5
- sdut-离散题目6
- sdut-离散题目7
- sdut-离散题目8
- sdut-离散题目9
- sdut-离散题目10
- sdut-离散题目12
- sdut-离散题目13
- [JavaEE] JPA中的Primary Key的几种生成方式
- HDU1069(DAG)
- 离散题目5
- Java float型数据判断是否相等
- Tomcat数据库连接池的配置方法总结
- SDUT 3805 离散题目11
- 读书的作用--引用《儒道至圣》小说章节
- JS中的caller属性
- VC中#pragma小结
- 夜神模拟器与Android studio连接
- Ubuntu桌面版如何像Windows一样使用软件桌面快捷方式
- Git 恢复操作
- jsp页面框中实现数据滚动形式
- cowboy源码分析