hdu 2034 人见人爱A-B
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=2034
人见人爱A-B
Description
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)
呵呵,很简单吧?
Input
如果n=0并且m=0表示输入的结束,不做处理。
Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
Sample Input
3 3 1 2 3 1 4 7
3 7 2 5 8 2 3 4 5 6 7 8
Sample Output
2 3
NULL
stl大法好。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::set;
using std::min;
using std::find;
using std::pair;
using std::vector;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 1010;
const int INF = 0x3f3f3f3f;
set<int> A, B;
vector<int> res;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int a, b, v;
while(~scanf("%d %d", &a, &b), a + b) {
rep(i, a + b) {
scanf("%d", &v);
if(i < a) A.insert(v);
else B.insert(v);
}
for(set<int>::iterator i = A.begin(); i != A.end(); ++i) {
if(B.find(*i) == B.end()) res.pb(*i);
}
int n = sz(res);
if(!n) { puts("NULL"); continue; }
rep(i, n) printf("%d ", res[i]);
putchar('\n');
A.clear(), B.clear(), res.clear();
}
return 0;
}
hdu 2034 人见人爱A-B的更多相关文章
- hdu 2034人见人爱A-B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2034 解题思路:set的基本用法 #include<iostream> #include& ...
- HDU 2034 人见人爱A-B 分类: ACM 2015-06-23 23:42 9人阅读 评论(0) 收藏
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 2034 人见人爱A-B【STL/set】
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- 杭电 2034 人见人爱A-B
http://acm.hdu.edu.cn/showproblem.php?pid=2034 人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hdu 2035 人见人爱A^B
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2035 人见人爱A^B Description 求A^B的最后三位数表示的整数.说明:A^B的含义是“A ...
- HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏
人见人爱A^B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 杭电2034——人见人爱A-B
#include <stdio.h> #include <algorithm> using namespace std; int main () { int a[110],b[ ...
- HDU 2033 人见人爱A+B
http://acm.hdu.edu.cn/showproblem.php?pid=2033 Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的 ...
- HDU 2035.人见人爱A^B-快速幂
人见人爱A^B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
随机推荐
- flex经验记录(转载)
最近一直忙于项目,很好抽出时间学习,刚忙里偷闲浏览博客看到一位博友总结的一些flex的经验,感觉不错就转载过来,一来扩散一下,二来保存下来,以后忘记的时候可以回来学习下. 原博文地址:http://b ...
- python基础(set)补充
1.函数参数(引用) 函数的传参,传的是引用 def func(args): args.appand(123) li=[11,22,33] func(li) print(li) [11,22,33, ...
- jQuery 的随机密码生成 .
$.extend({ password: function (length, special) { var iteration = 0; var password = ""; va ...
- asp.net(c#)修改时的赋值操作
赋值操作方法(将信息显示至文本框中): public void Show_Infobase(int _peoid) { DataSet ds = new DataSet(); ds = platbll ...
- python函数基础以及函数参数简解
python中函数分为函数.内置函数Python所有的内置函数 自定义函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. ...
- CSS用border绘制三角形
使用border绘制三角形的思路,就是border尺寸设置一个较大的值,元素自身的宽高设置为0,全部由边线占据,这样每边就会显示为四分之一块的三角形.这样不借助图片,可以直接绘制出三角形了. 一个栗子 ...
- SVN 外部引用(svn:externals)处理相似系统的公用代码
一.创建外部引用 我们常常遇到这样一个场景,我们有两个系统,两个系统用的是同一套框架.如果我们用两套程序 去做,当我们修改这个公共的框架的时候,另外一个还是旧版本的,很容易造成混乱. SVN的外部用就 ...
- 图解Windows Server 2012 桌面图标
显示桌面图标.壁纸等 1 WIN键+R键,输入: rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0 选择你需要的图标显示到桌面去,如下图所示 ...
- Java移位运算
java中移位运算符有三种“<<”.“>>”.“>>>”,没有“<<<”运算符. “<<”运算符将二进制位进行左移,低位用0来填 ...
- 使用NPOI操纵Excle,并输入到客户端
NPOI下载:http://files.cnblogs.com/files/gosky/NPOI_2.2.0.0.zip 导入以下5个引用: ICSharpCode.SharpZipLib.dll N ...