light oj 1149 - Factors and Multiples (二分匹配)
来源:互联网 发布:修复dll软件 编辑:程序博客网 时间:2024/05/18 02:07
题目链接:http://lightoj.com/volume_showproblem.php?problem=1149
You will be given two sets of integers. Let's call them set A and set B. Set A contains n elements and set B contains m elements. You have to remove k1 elements from set A and k2 elements from set B so that of the remaining values no integer in set B is a multiple of any integer in set A. k1 should be in the range [0, n] and k2 in the range [0, m].
You have to find the value of (k1 + k2) such that (k1 + k2) is as low as possible. P is a multiple of Q if there is some integer K such that P = K * Q.
Suppose set A is {2, 3, 4, 5} and set B is {6, 7, 8, 9}. By removing 2 and 3 from A and 8 from B, we get the sets {4, 5} and {6, 7, 9}. Here none of the integers 6, 7 or 9 is a multiple of 4 or 5.
So for this case the answer is 3 (two from set A and one from set B).
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
The first line of each case starts with an integer n followed by n positive integers. The second line starts with m followed by m positive integers. Both n and m will be in the range [1, 100]. Each element of the two sets will fit in a 32 bit signed integer.
Output
For each case of input, print the case number and the result.
Sample Input
Output for Sample Input
2
4 2 3 4 5
4 6 7 8 9
3 100 200 300
1 150
Case 1: 3
Case 2: 0
题目大意: 主要是看图片上的那个小孩,看看图片,看看样例,大概就是二分匹配的题; 输入两组数,
第二组的数是第一组数任意一个的倍数,表明两者有关系,比如样例中的 6 是2、3 的倍数,
表明有关系,求最大的匹配数
解析: 基本二分匹配
代码如下:
#include<iostream>#include<algorithm>#include<map>#include<string>#include<cstdio>#include<cstring>#include<cctype>#include<cmath>#define N 1009using namespace std;const int inf = 0x3f3f3f3f;const int mod = 1000003;int mp[N][N], used[N], match[N], m, n;int Find(int u){ for(int i = 1; i <= n; i++) { if(!used[i] && mp[u][i]) { used[i] = 1; if(match[i] == -1 || Find(match[i])) { match[i] = u; return 1; } } } return 0;}int main(){ int a[N], b[N]; int t, cnt = 0, i, j; cin >> t; while(t--) { scanf("%d", &n); for(i = 1; i <= n; i++) { scanf("%d", &a[i]); } scanf("%d", &m); for(i = 1; i <= m; i++) { scanf("%d", &b[i]); } memset(mp, 0, sizeof(mp)); memset(match, -1, sizeof(match)); for(i = 1; i <= m; i++) for(j = 1; j <= n; j++) if(b[i] % a[j] == 0) mp[i][j] = 1; int ans = 0; for(i = 1; i <= m; i++) { memset(used, 0, sizeof(used)); ans += Find(i); } printf("Case %d: %d\n", ++cnt, ans); }}
- light oj 1149 - Factors and Multiples (二分匹配)
- Light oj 1149 - Factors and Multiples 【二分图最大匹配】【好题】
- Light oj 1149--Factors and Multiples【二分匹配 && 经典建图】
- Light oj 1149 - Factors and Multiples【最大匹配】
- LightOJ - 1149 Factors and Multiples(二分图匹配)
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- Factors and Multiples(二分图匹配)LightOJ
- UVa11159 - Factors and Multiples(二分匹配)
- LightOJ--1149--Factors and Multiples(二分图好题)
- UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
- lightoj1149 - Factors and Multiples【二分图最大匹配】
- LightOJ 1149 Factors and Multiples 最大匹配--匈牙利算法
- uva 11159 Factors and Multiples
- uva 11159 Factors and Multiples
- UVA 11159Factors and Multiples (最大独立集)
- LightOJ 1149 Factors and Multiples【最小点覆盖】(这些图论专题的题目都好裸啊)
- 【Light-oj】-Expanding Rods(二分&几何)
- 【light-oj】-’1307 - Counting Triangles(二分)
- IDEA 32位正常,64位双击没反应,打不开
- hdu1498 大水题
- 【43】左旋转字符串
- C和C++中const区别
- log4j、spring MVC简介
- light oj 1149 - Factors and Multiples (二分匹配)
- hadoop: Could not resolve hostname ***
- RTMP协议
- 统计工龄 模拟EXCEL排序 银行排队问题之单队列多窗口问题 银行业务队列简单模拟 堆栈操作合法性 两个有序序列的中位数
- 中国惠普前总裁孙振耀的毕生经验之谈
- Python Twisted
- android程序开机自启
- 键盘遮挡输入框的问题
- Saltstack数据系统-Pillar