大水题。。

求集合的并

 /*

 */
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int inf = 0x3f3f3f3f;
const double pi=acos(-1.0);
const int dx[]={,-,,};
const int dy[]={,,,-};
const double eps = 1e-;
const int maxm = ;
const int maxn = ; int a[ maxn ],b[ maxn ]; int main(){
int n,m;
while( scanf("%d%d",&n,&m)== ){
for( int i=;i<n;i++ ){
scanf("%d",&a[i]);
}
for( int i=;i<m;i++ ){
scanf("%d",&b[i]);
}
sort( a,a+n );
sort( b,b+m );
int cur = -;
int ai = ;
int bi = ;
while( ai<n || bi<m ){
if( ai==n ){
for( int i=bi;i<m;i++ ){
if( b[ i ]==cur ) continue;
else {
cur = b[ i ];
printf(" %d",cur);
}
}
break;
}
if( bi==m ){
for( int i=ai;i<n;i++ ){
if( a[ i ]==cur ) continue;
else {
cur = a[ i ];
printf(" %d",cur);
}
}
break;
}
if( cur==- ){
if( a[ai]<b[bi] ){
cur = a[ ai ];
ai ++;
}
else if( a[ai]==b[bi] ){
cur = a[ ai ];
ai ++;
bi ++;
}
else {
cur = b[ bi ];
bi ++;
}
printf("%d",cur);
}
else {
if( a[ai]<b[bi]&&a[ai]>cur ){
cur = a[ ai ];
ai ++;
printf(" %d",cur);
}
else if( a[ai]==b[bi]&&a[ai]>cur ){
cur = a[ ai ];
ai ++;
bi ++;
printf(" %d",cur);
}
else if( a[ai]>b[bi]&&b[bi]>cur ){
cur = b[bi];
bi ++;
printf(" %d",cur);
}
}
}
printf("\n");
}
return ;
}

HDU1412的更多相关文章

  1. (Set){A} + {B} hdu1412

    {A} + {B} 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1412   Problem Description 给你两个集合,要求{A} + {B} ...

  2. HDU1412:{A} + {B}

    Problem Description 给你两个集合,要求{A} + {B}. 注:同一个集合中不会有两个相同的元素.   Input 每组输入数据分为三行,第一行有两个数字n,m(0<n,m& ...

  3. STL应用——hdu1412(set)

    set函数的应用 超级水题 #include <iostream> #include <cstdio> #include <algorithm> #include ...

  4. HDU1412 {A} + {B}

    2019-05-17 10:15:01 每个元素之间有一个空格隔开. 每行最后一的元素后面没有空格,区别于HDU人见人爱A - B 注意使用STL的时候要清空 .  a.clear(); #inclu ...

  5. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

  6. STL使用————SET&MULTISET

    SET函数的基本用法 by hhl 使用set的好处 1. 当增加元素后,集合会自动删重并从小到大排列(时间比快排还快)2. 相当于一棵伸展树(能快速求出后继) 使用基础 #include<se ...

随机推荐

  1. SQL Server 中WITH (NOLOCK)浅析(转潇湘隐者)

    博文出处:http://www.cnblogs.com/kerrycode/p/3946268.html 概念介绍 开发人员喜欢在SQL脚本中使用WITH(NOLOCK), WITH(NOLOCK)其 ...

  2. 关于ThinkRock中的Topics

    thinkrock是一款非常优秀的思想管理软件 主题是用来分类思想的,从而将思想具体化 比如:个人,书籍,小孩等等 在其中红色以及灰色是不推荐使用的,因为有别的意思.

  3. javascript笔记——jikeytang javascript前端群 389875212 精华总结

    网址: https://github.com/jsfront   //    http://www.kancloud.cn/jsfront/month/82796 内容: 前端js github总结, ...

  4. JetBRAINS 系列注册机

    转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/1118/ 说明 这个是一国外的大牛写的一个 JetBRAINS 系列注册机,他里面包含了很多,我就不打字了. ...

  5. random between [a,b]、(a,b]、[a,b)

    #include <iostream> #include <ctime> #include <cstdlib> using namespace std; ; /*c ...

  6. 广度优先算法BFS

    package myalgorithm; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; / ...

  7. 使用AE进行点的坐标投影变换

    private IPoint PRJtoGCS( double x, double y) { IPoint pPoint = new PointClass(); pPoint.PutCoords(x, ...

  8. 【转】winform与web 按钮button去掉边框

    ref:http://blog.csdn.net/wangzh300/article/details/5264316 WinForm的话 设置Button属性的FlatStyle为Flat,并且设置F ...

  9. CURL的使用<发送与接收数据>

    $headers = array( "TYPE:xxxxooooo", "TOKEN:00000000" ); $data = array( 'data' =& ...

  10. 用JS写的放大镜

    代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...