-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloj1198.cpp
108 lines (101 loc) · 2.7 KB
/
loj1198.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
97
98
99
100
101
102
103
104
105
106
107
108
//{ Template
using namespace std;
//{ C-headers
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cassert>
#include <ctime>
//}
//{ C++-headers
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
//}
//{ Loops
#define forab(i,a,b) for (__typeof(b) i = (a); i <= (b); ++i)
#define rep(i,n) forab (i, 0, (n) - 1)
#define For(i,n) forab (i, 1, n)
#define rofba(i,a,b) for (__typeof(b) i = (b); i >= (a); --i)
#define per(i,n) rofba (i, 0, (n) - 1)
#define rof(i,n) rofba (i, 1, n)
#define forstl(i,s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
//}
//{ Floating-points
#define EPS DBL_EPSILON
#define abs(x) (((x) < 0) ? - (x) : (x))
#define zero(x) (abs (x) < EPS)
#define equal(a,b) (zero ((a) - (b)))
#define PI 2 * acos (0.0)
//}
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define memo(a,v) memset(a,v,sizeof(a))
#define all(a) a.begin(),a.end()
#define INF 1<<29
#define ll long long
#define db double
#define pii pair<int ,int >
#define NL puts("")
#define G getchar()
//}
bool cmp(int a, int b)
{
return a>b;
}
int main () {
int t, cs,n,a[55],b[55],i,ans,j,Case=1;
bool visa[55],visb[55];
scanf("%d",&t);
For (cs, t) {
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<n;i++) {
scanf("%d",&b[i]);
visa[i] = visb[i] = false;
}
sort(a,a+n);
sort(b,b+n,cmp);
ans=0;
for(i=0;i<n;i++)
{
j=0;
while(j<n&&(a[i]<=b[j]||visb[j]))
j++;
if(j<n)
{
visb[j]=visa[i]=true;
ans+=2;
}
}
for(i=0;i<n;i++)
{
if(visa[i]==false)
{
for(j=0;j<n;j++)
{
if(visb[j]==false&&a[i]==b[j])
{
visa[i]=visb[j]=true;
ans+=1;
break;
}
}
}
}
printf("Case %d: %d\n",Case++,ans);
}
return 0;
}