lightoj1149 - Factors and Multiples【二分图最大匹配】
来源:互联网 发布:网络歌手灰色天空 编辑:程序博客网 时间:2024/06/07 12:33
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
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#define inf 0x3f3f3f3fusing namespace std;const int maxn=110;int n,m;int p[maxn];int numa[maxn];int numb[maxn];bool vis[maxn];bool find(int k){for(int i=0;i<m;++i){if(!vis[i]&&numb[i]%numa[k]==0){vis[i]=true;if(p[i]==-1||find(p[i])){p[i]=k;return true;}}}return false;}int main(){int i,j,k=1,t;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;++i){scanf("%d",&numa[i]);}scanf("%d",&m);for(i=0;i<m;++i){scanf("%d",&numb[i]);}int ans=0;memset(p,-1,sizeof(p));for(i=0;i<n;++i){memset(vis,false,sizeof(vis));if(find(i))ans++;}printf("Case %d: %d\n",k++,ans);}return 0;}
- lightoj1149 - Factors and Multiples【二分图最大匹配】
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- Light oj 1149 - Factors and Multiples 【二分图最大匹配】【好题】
- LightOJ - 1149 Factors and Multiples(二分图匹配)
- Factors and Multiples(二分图匹配)LightOJ
- UVa11159 - Factors and Multiples(二分匹配)
- UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
- light oj 1149 - Factors and Multiples (二分匹配)
- Light oj 1149 - Factors and Multiples【最大匹配】
- LightOJ 1149 Factors and Multiples 最大匹配--匈牙利算法
- Light oj 1149--Factors and Multiples【二分匹配 && 经典建图】
- LightOJ--1149--Factors and Multiples(二分图好题)
- UVA 11159Factors and Multiples (最大独立集)
- uva 11159 Factors and Multiples
- uva 11159 Factors and Multiples
- HDU1068Girls and Boys二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配 。
- git的基本使用
- linux下C语言基础学习笔记2
- return和exit
- 高中同学聚会有感
- ios开发——UITextView展示txt电子书时的页数调整
- lightoj1149 - Factors and Multiples【二分图最大匹配】
- x86 系列 CPU 内存寻址模式总结
- 位置无关(PIC)代码原理剖析
- JS选取DOM元素的方法
- 跨域(二级域)session共享
- 上移、下移功能
- 云计算技术知识点集锦
- Fast Rcnn 主要架构
- 1017. A除以B (20)