-
Notifications
You must be signed in to change notification settings - Fork 1
/
11678 Card's Exchange.cpp
executable file
·96 lines (80 loc) · 1.6 KB
/
11678 Card's Exchange.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <bitset>
using namespace std;
int x[10000];
int y[10000];
bitset<100001> xS;
bitset<100001> yS;
int d_val(int a[], int l, int b)
{
int o = 0;
for ( int i = 0 ; i < l ; i++)
{
if (b == 1 )// setting x
{
if(xS[a[i]] == 1)
{
o++;
xS[a[i]] = 0;
}
}
else
{
if ( yS[a[i]] == 1)
{
o++;
yS[a[i]] = 0;
}
}
}
return o;
}
int res(int arr[] , int l, int b)
{
int o = 0;
for ( int i = 0 ; i < l ; i++)
{
if ( b == 1)// x is less
{
if (yS[arr[i]] == 1)
{
o++;
yS[arr[i]] = 0;
}
}
else
{
if ( xS[arr[i]] == 1)
{
o++;
xS[arr[i]] = 0;
}
}
}
return o;
}
int main()
{
while (true )
{
xS.set();
yS.set();
int a , b;
cin >> a >>b;
if( a == b && a == 0)
return 0;
for ( int i = 0 ; i < a ; i++)
cin >> x[i];
for ( int i = 0 ; i < b ; i++)
cin >> y[i];
int dX = d_val(x , a, 1);
int dY = d_val(y , b, 2);
int r;
if ( dX < dY )
r = res(x , a, 1);
else
r = res( y , b, 2);
cout << r << endl;
}
return 0;
}