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 ...
随机推荐
- 没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的
引发原因:项目启动时,前端调用 wcf地址,引用的地址访问无法在 IIS Express找到导致该错误 解决方法,找出前端的web.config 查看引用的项目是什么地址开头,如 localho ...
- x86_64 Ubuntu 14.04 LST安装gcc4.1.2 转载
由于编译源码软件需要用到gcc4.1.2版本,但是本机已经安装有gcc4.8.4,下载gcc4.1.2源码编译总会出现运行找不到库文件错误,或者i386和x86_64不兼容问题,在http://ask ...
- Android多线程异步处理:AsyncTask 的实现原理
AsyncTask主要用来更新UI线程,比较耗时的操作可以在AsyncTask中使用. AsyncTask是个抽象类,使用时需要继承这个类,然后调用execute()方法.注意继承时需要设定三个泛型P ...
- jquery获取对象
1.JQuery的核心的一些方法 $("Element").length; ‘元素的个数,是个属性 $("Element").size(); ’也是元素的个数, ...
- 使用Apache CXF开发WebServices服务端、客户端
在前一篇的博客中,我使用Xfire1.x来开发了WebServies的服务端. 但是如果你访问Apache的官网,可以看到xfire已经被合并了. 最新的框架叫做CXF. Apache CXF = C ...
- Ax Lookup Form
Reference: Class\sysLookupTable 1. 用临时表构造Lookup下拉结果,sysLookupTable有一个parmTmpBuffer方法,表明传入展示的结果集是临时表 ...
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
------------------------------------------------------------------------------------ js 获取当前日期时间 格式为 ...
- 用IKVMC将jar转成dll供c#调用
用IKVMC将jar转成dll供c#调用 ikvmc c# dll jar 用IKVMC将jar转成dll供c#调用 前言 ikvmc介绍 ikvmc下载安装 下载并解压 设置环境变量 jar-> ...
- 取得Android平台某设备上所有可用的Sensors
本来要写一个检测手机的温度的小应用,学习一下传感器的api,可结果怎么写不行.经检测,发现取得的Sensor为NULL,这才明白,我手机没有TYPE_AMBIENT_TEMPERATURE传感器. 于 ...
- 使用userdel命令删除Linux用户
serdel是什么 userdel 是一个底层用于删除用户的工具.在 Debian 上,我们通常会使用 deluser 命令.userdel 会查询系统账户文件,例如 /etc/password 和 ...