Matchmaker

题目描述:
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.

Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.

input:
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.

Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker’s color and diameter, correspondingly.

Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.

output:
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.

example:
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0

题目大意:
给我们n+m个圆盘,每个圆盘有颜色和直径,如果能在后m个圆盘中找到和前n个中某个直径相同,颜色相同的圆盘匹配那这就算一个beautifully closed,如果直径相同颜色不同就是close,斌且每个圆盘只能用一次,我们要找出有最多有多少个beautifully closed,并且输出close+beautifully closed的总数和beautifully closed的数量
直接上代码;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>

using namespace std;
const int maxn = 1e3+10;

int A[maxn][maxn],B[maxn];
int x,y;

int main () {
	int n,m;
	cin >> n >> m;	
	for(int i = 1;i <= n;i++) {
		scanf("%d %d",&x,&y);
		A[x][y]++;//记录下某种颜色,直径的圆盘的数量
		B[y]++;//记录下某个直径的圆盘数量
	}

	
	int ans = 0,sum = 0;
	for(int i = 1;i <= m;i++) {
		scanf("%d %d",&x,&y);
		if(A[x][y]) {//如果相应颜色,直径的圆盘存在则和他匹配
			A[x][y]--;
			ans++;
		}
		if(B[y]) {//如果相应直径的圆盘存在则和他匹配
			B[y]--;
			sum++;
		}
	}
	cout << sum << " " << ans << "\n";
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值