HDU1412
大水题。。
求集合的并
/* */
#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的更多相关文章
- (Set){A} + {B} hdu1412
{A} + {B} 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1412 Problem Description 给你两个集合,要求{A} + {B} ...
- HDU1412:{A} + {B}
Problem Description 给你两个集合,要求{A} + {B}. 注:同一个集合中不会有两个相同的元素. Input 每组输入数据分为三行,第一行有两个数字n,m(0<n,m& ...
- STL应用——hdu1412(set)
set函数的应用 超级水题 #include <iostream> #include <cstdio> #include <algorithm> #include ...
- HDU1412 {A} + {B}
2019-05-17 10:15:01 每个元素之间有一个空格隔开. 每行最后一的元素后面没有空格,区别于HDU人见人爱A - B 注意使用STL的时候要清空 . a.clear(); #inclu ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
- STL使用————SET&MULTISET
SET函数的基本用法 by hhl 使用set的好处 1. 当增加元素后,集合会自动删重并从小到大排列(时间比快排还快)2. 相当于一棵伸展树(能快速求出后继) 使用基础 #include<se ...
随机推荐
- 第八篇、微信小程序-progress组件
主要属性: 效果图: ml: <View > <!--百分比是30,并在进度条右侧显示百分比--> <Text class="text-style"& ...
- (转)DES、RSA、MD5、SHA、随机生成加密与解密
一.数据加密/编码算法列表 常见用于保证安全的加密或编码算法如下: 1.常用密钥算法 密钥算法用来对敏感数据.摘要.签名等信息进行加密,常用的密钥算法包括: DES(Data Encr ...
- 【Leetcode】355. Design Twitter
题目描述: Design a simplified version of Twitter where users can post tweets, follow/unfollow another us ...
- .Net Core 项目中的包引用探索(使用VSCode)
本文组织有点乱,先说结论吧: 1 在 project.json 文件中声明包引用. 而不是像以前那样可以直接引用 dll. 2 使用 dotnet restore 命令后,nuget 会把声明的依赖项 ...
- JDK中工具类的使用
JDK中内置了很多常用的工具类,且多以“s”结尾,如:集合工具类Collections,数组工具类Arrays,对象工具类Objects,文件工具类Files,路径工具类Paths,数学工具类Math ...
- jQuery学习-----(一)JQuery的'$'符号用法
1.jQuery的三种$() 1)$()可以是$(expresion),即css选择器.Xpath或html元素,也就是通过上述表达式来匹配目标元素. 比如:$("a")构造的 ...
- Android 使用日常
如何让Android Studio的智能感知不区分大小写? http://ask.csdn.net/questions/155844
- Setfocus - IE 需要使用setTimeout
setTimeout(function () { $('#controlid').focus(); }, 100); document.getElementById('filterPopupInput ...
- 彻底删除sql server的方法
请先确定是否把sql相关的东西删了,建议进行如下操作. 1.先下个Windows Install Clean Up,清理sql相关东西,要全部清理. 2.到控制面板--添加删除程序中看是否还有未删的. ...
- laravel--上传
1.视图里面 2.控制器里面 //收集表单提交数据 $input = $request->all(); //查看是否有图片提交上来 if ($request->hasFile('title ...