1.小球匹配
题库链接: https://nanti.jisuanke.com/t/T3566
解题思路:
我是这样想的,统计A和B中各种小球的个数,然后相同种类(即x=y)的小球中,在A中该种类小球个数和B中该种类小球的个数两者间取较小值,就是该种类小球的最多配对对数,然后把各种种类的小球都这样操作一遍就能得到答案了。
代码:
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int n, m, sum;
map <long long, int> A;
map <long long, int> B;
long long Min(long long x, long long y) {
if (x < y) {
return x;
}
return y;
}
int main() {
freopen("ball.in", "r", stdin);
freopen("ball.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
A[x]++;
}
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
B[x]++;
}
for (map<long long