UVa 496 Simply Subsets (STL&set_intersection)
来源:互联网 发布:怎么样入驻淘宝达人 编辑:程序博客网 时间:2024/04/29 21:18
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=437
先介绍<algorithm>头文件中与集合运算有关的4个函数:
- set_union
- Union of two sorted ranges (并集:A∪B)
- set_intersection
- Intersection of two sorted ranges (交集:A∩B)
- set_difference
- Difference of two sorted ranges (差集:A-B)
- set_symmetric_difference
- Symmetric difference of two sorted ranges (对称差集:A△B)
很明显,这里要判断两个集合的关系,使用交集来判断就行了。
使用方法:
set_intersection(a, a + n, b, b + m, v.begin());这里v是动态数组,用于保存交运算结果。(其他函数的使用方法均与之类似)
该函数的返回值减去v.begin()就是集合的大小。
完整代码:
/*0.016s*/#include<bits/stdc++.h>using namespace std;int a[100], b[100];vector<int> v(100);///初始化空间是必须的int main(){int n, m, cnt, diff;char ch;while (~scanf("%d%c", &a[0], &ch)){for (n = 1; ch != 10; ++n)scanf("%d%c", &a[n], &ch);cnt = scanf("%d%c", &b[0], &ch);for (m = 1; ch != 10 && cnt == 2; ++m)cnt = scanf("%d%c", &b[m], &ch);sort(a, a + n);sort(b, b + m);diff = set_intersection(a, a + n, b, b + m, v.begin()) - v.begin();if (diff == min(n, m)){if (n < m) puts("A is a proper subset of B");else if (n > m) puts("B is a proper subset of A");else puts("A equals B");}else if (diff) puts("I'm confused!");else puts("A and B are disjoint");}return 0;}
- UVa 496 Simply Subsets (STL&set_intersection)
- UVa 496 - Simply Subsets
- uva498 Simply Subsets
- STL set_difference set_intersection set_union 操作
- Uva 10235 - Simply Emirp
- UVa 10235 - Simply Emirp
- UVA 12576 Simply Loopy
- set_intersection
- set_intersection
- C++ STL merge,set_union,set_intersection,set_difference,set_symmetric_difference
- STL 之includes,set_intersection,set_union,set_difference,set_symmetric_difference
- STL algorithm算法set_difference,set_intersection(53)
- STL 之includes,set_intersection,set_union,set_difference,set_symmetric_difference
- STL之set_union、set_intersection、set_difference、set_symmetric_difference
- UVA 12576 - Simply Loopy
- std::set_intersection
- set_union set_intersection
- Subsets
- VIM常用命令
- 绳子可以覆盖的最多点数
- 最佳vim技巧
- Ecological Premium
- 安卓模拟器SDCARD read-only解决方法
- UVa 496 Simply Subsets (STL&set_intersection)
- Ajax程序:处理异步调用中的异常(使用Asp.Net Ajax内建的异常处理方法)
- VIM正则表达式
- UEFI启动模式和传统的Lagency启动模式
- C++ 计算系列二
- Android 轻松实现语音识别
- GamingAnywhere 一:GA初览
- 空白的视图
- VC++学习心得系列