lightoj 1184 Marriage Media [二分图匹配]
来源:互联网 发布:乐视mac 编辑:程序博客网 时间:2024/04/29 23:53
Description
You run a marriage media. You take some profiles for men and women, and your task is to arrange as much marriages as you can. But after reading their bio-data you have found the following criteria.
1. No man will marry a woman if their height gap is greater than 12 inches.
2. No woman will marry a man if their age gap is greater than 5 years.
3. A couple can be formed if either both are not divorced or both are divorced.
4. Of course, a man can marry a single woman and vice versa.
Now you are given the bio-data of some men and women, you have to arrange the maximum number of marriages considering the given criteria.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case contains two integer m, n (1 ≤ m, n ≤ 50). Each of the next m lines will contain the information for a man, and each of the next n lines will contain the information for a woman. An information will contain three integers denoting the height in inches, age in years and 1 or 0 depending on they are divorced or not respectively. Assume that Height will be between 50 and 80, age will be between 20 and 50.
Output
For each case, print the case number and the maximum number of marriages you can arrange.
Sample Input
2
2 2
70 30 0
60 20 0
71 25 0
71 35 0
1 1
70 30 1
70 30 0
Sample Output
Case 1: 2
Case 2: 0
题目大意:给你n个男的,m个女的 ; 男的和女的体重差不能超过15,年龄差不能超过5,婚姻状态必须相同,求满足个数;
AC代码:
#include <bits/stdc++.h>using namespace std ;int ma[500][500] , link[500] , vis[500] , n , m ;int age[500] , wei[500] , marry[500] ;int find( int x){ for(int i = 1 ; i <= m;i++) { if(!vis[i]&&ma[x][i]==1) { vis[i] = 1 ; if(!link[i]||find(link[i])) { link[i] = x ; return 1 ; } } } return 0 ;}int main(){ int t ,ans , count = 1; cin>>t; while(t--) { memset(ma,0,sizeof(ma)); memset(link,0,sizeof(link)); cin>>n>>m; ans = 0 ; for(int i = 1 ; i <=n+m;i++) cin>>wei[i]>>age[i]>>marry[i]; for(int i = 1 ; i<=n ; i++) { for(int j =1 ; j<=n+m;j++) { if(abs(wei[i]-wei[j])<=12) if(abs(age[i]-age[j])<=5) if(marry[i]==marry[j]) ma[i][j-n] = 1 ; } } for(int i = 1 ; i <=n ; i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("Case %d: %d\n",count++,ans); } return 0 ;}
- lightoj 1184 Marriage Media [二分图匹配]
- LightOJ 1184 - Marriage Media 【二分图最大匹配】
- LightOJ - 1184 Marriage Media(二分图匹配)
- LightOJ 1184 Marriage Media 最大匹配-匈牙利算法
- LightOJ 1011 Marriage Ceremonies (二分图最优匹配 状态压缩+记忆化搜索)
- lightoj 1061 KM 二分图匹配
- LightOJ 1209 - Strange Voting 【二分图匹配】
- LightOJ - 1152 Hiding Gold(二分图匹配)
- 稳定婚姻问题 Poj 3487 The Stable Marriage Problem + Hdu 1522 Marriage is Stable (二分图稳定匹配)
- HDU - 3081 Marriage Match II(二分图最大匹配 + 并查集)
- HDU-3081-Marriage Match II【并查集】【二分图匹配】
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- LightOJ - 1149 Factors and Multiples(二分图匹配)
- Factors and Multiples(二分图匹配)LightOJ
- lightoj 1011 Marriage Ceremonies
- LightOJ 1011 - Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- 多线程基础
- Cocos2d-x的学习 触碰事件老版本和新版本的对比 第一节
- sql 插入一条记录并查询出记录的id值
- 防止快速重复点击的代码
- java实现Pub/Sub
- lightoj 1184 Marriage Media [二分图匹配]
- JavaWeb开发模型
- 将硬盘中两个TXT文件读出来,并写入另一个文件
- 利用jQuery框架设置页面弹出层
- php如何获取当前的url
- Android Fresco监听回调,成功调回Bitmap
- Spark Insert Hbase解决task not to serializable
- 一步步教你使用Hexo配合github搭建个人主页
- PCA计算过程