题意是有很多种颜色的 的袜子 也分左右脚
让我们用最少操作 完成配对。
也就是要 1 颜色配对 2 左右脚配对。
这题找了很多的题解。。都是思路很费劲。。
在cf提交区看到一种份代码。非常nice 一目了然。。
就放在这里吧。
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0)
#define endl '\n'
#define int long long
#define ar array<int, 2>
#define arr array<int, 3>
const int N = 2e5 + 5, M = 2 * N;
const int inf = 0x3f3f3f3f;
int mod = 998244353; //1e9+7;
int t, n, m, k;
// 规定正负脚 多的为正 少的为负。。特别方便。。
signed main()
{
ios;
#ifdef DEBUG
freopen("../1.in", "r", stdin);
#endif
cin >> t;
while (t--)
{
int l, r;
cin >> n >> l >> r;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
if (i <= l)
a[x]++;
else
a[x]--;
}
if (l < r)
{
swap(l, r);
for (int i = 1; i <= n; ++i)
a[i] = -a[i];
}
int ans = 0, c = (l - r) >> 1;
for (int i = 1; i <= n; ++i)
while (a[i] >= 2 && c)
{
c--, a[i] -= 2, ans++;
}
for (int i = 1; i <= n; ++i)
if (a[i] > 0)
ans += a[i];
cout << ans << endl;
}
};