HDU1412
大水题。。
求集合的并
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 3 */ 4 #include<algorithm> 5 #include<iostream> 6 #include<string.h> 7 #include<stdlib.h> 8 #include<stdio.h> 9 #include<math.h> 10 #include<queue> 11 #include<stack> 12 #include<map> 13 #include<set> 14 using namespace std; 15 typedef long long int64; 16 //typedef __int64 int64; 17 typedef pair<int64,int64> PII; 18 #define MP(a,b) make_pair((a),(b)) 19 const int inf = 0x3f3f3f3f; 20 const double pi=acos(-1.0); 21 const int dx[]={1,-1,0,0}; 22 const int dy[]={0,0,1,-1}; 23 const double eps = 1e-8; 24 const int maxm = 1005; 25 const int maxn = 10005; 26 27 int a[ maxn ],b[ maxn ]; 28 29 int main(){ 30 int n,m; 31 while( scanf("%d%d",&n,&m)==2 ){ 32 for( int i=0;i<n;i++ ){ 33 scanf("%d",&a[i]); 34 } 35 for( int i=0;i<m;i++ ){ 36 scanf("%d",&b[i]); 37 } 38 sort( a,a+n ); 39 sort( b,b+m ); 40 int cur = -99999999; 41 int ai = 0; 42 int bi = 0; 43 while( ai<n || bi<m ){ 44 if( ai==n ){ 45 for( int i=bi;i<m;i++ ){ 46 if( b[ i ]==cur ) continue; 47 else { 48 cur = b[ i ]; 49 printf(" %d",cur); 50 } 51 } 52 break; 53 } 54 if( bi==m ){ 55 for( int i=ai;i<n;i++ ){ 56 if( a[ i ]==cur ) continue; 57 else { 58 cur = a[ i ]; 59 printf(" %d",cur); 60 } 61 } 62 break; 63 } 64 if( cur==-99999999 ){ 65 if( a[ai]<b[bi] ){ 66 cur = a[ ai ]; 67 ai ++; 68 } 69 else if( a[ai]==b[bi] ){ 70 cur = a[ ai ]; 71 ai ++; 72 bi ++; 73 } 74 else { 75 cur = b[ bi ]; 76 bi ++; 77 } 78 printf("%d",cur); 79 } 80 else { 81 if( a[ai]<b[bi]&&a[ai]>cur ){ 82 cur = a[ ai ]; 83 ai ++; 84 printf(" %d",cur); 85 } 86 else if( a[ai]==b[bi]&&a[ai]>cur ){ 87 cur = a[ ai ]; 88 ai ++; 89 bi ++; 90 printf(" %d",cur); 91 } 92 else if( a[ai]>b[bi]&&b[bi]>cur ){ 93 cur = b[bi]; 94 bi ++; 95 printf(" %d",cur); 96 } 97 } 98 } 99 printf("\n"); 100 } 101 return 0; 102 }
keep moving...