LightOJ--1149--Factors and Multiples(二分图好题)
来源:互联网 发布:linux 如何安装xampp 编辑:程序博客网 时间:2024/06/08 18:49
SubmitStatus
Description
You will be given two sets of integers. Let's call them set A and setB. Set A contains n elements and setB contains m elements. You have to remove k1 elements from set A and k2 elements from setB so that of the remaining values no integer in set B is a multiple of any integer in setA. 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 ofQ 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 integers6, 7 or 9 is a multiple of 4 or5.
So for this case the answer is 3 (two from setA 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 byn positive integers. The second line starts with m followed bym 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
2
4 2 3 4 5
4 6 7 8 9
3 100 200 300
1 150
Sample Output
Case 1: 3
Case 2: 0
Source
给了两个集合A,B,分别有n,m个数,从A取k1个数,B取k2个数,使得b[ j ]%a[ i ]==0的情况不存在
刚开始以为可以暴力的,但是后来发现暴力真的是挺麻烦,把图画出来之后会发现,其实就是最小点覆盖,二分图性质:最小点覆盖=最大匹配,匈牙利算法跑一次
#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespace std;vector<int>map[200];int used[200],pipei[200],a[200],b[200];int n,m;int find(int x){for(int i=0;i<map[x].size();i++){int y=map[x][i];if(!used[y]){used[y]=1;if(pipei[y]==-1||find(pipei[y])){pipei[y]=x;return 1;}}}return 0;}int main(){int t,k=1;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(pipei,-1,sizeof(pipei));scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&a[i]);map[i].clear();}scanf("%d",&m);for(int i=0;i<m;i++)scanf("%d",&b[i]);for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(b[j]%a[i]==0){map[i].push_back(j);}}}int sum=0;for(int i=0;i<n;i++){memset(used,0,sizeof(used));sum+=find(i);}printf("Case %d: %d\n",k++,sum);}return 0;}
- LightOJ--1149--Factors and Multiples(二分图好题)
- LightOJ - 1149 Factors and Multiples(二分图匹配)
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- Factors and Multiples(二分图匹配)LightOJ
- light oj 1149 - Factors and Multiples (二分匹配)
- LightOJ 1149 Factors and Multiples 最大匹配--匈牙利算法
- UVa11159 - Factors and Multiples(二分匹配)
- LightOJ 1149 Factors and Multiples【最小点覆盖】(这些图论专题的题目都好裸啊)
- Light oj 1149 - Factors and Multiples 【二分图最大匹配】【好题】
- Light oj 1149--Factors and Multiples【二分匹配 && 经典建图】
- UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
- lightoj1149 - Factors and Multiples【二分图最大匹配】
- uva 11159 Factors and Multiples
- uva 11159 Factors and Multiples
- Light oj 1149 - Factors and Multiples【最大匹配】
- UVA 11159Factors and Multiples (最大独立集)
- lightoj 1135 - Count the Multiples of 3(线段树)
- Problem1(Multiples of 3 and 5)
- 为已有的web project项目加入maven支持,并使用myeclipse的插件.
- sp<> wp<>-Android中定义了两种智能指针强指针sp和弱指针wp
- RUST语法
- hdu3342 Legal or Not(简单拓扑排序判定)
- 圆形ImageView系列(一)-----Xfermode+View
- LightOJ--1149--Factors and Multiples(二分图好题)
- Android自定义属性限制
- ActionInvoker
- 如何在Java中对MongoDB按日期进行查询统计
- 〖原创〗使用Docker过程中注意事项之壹(文章末尾有彩蛋!)
- 【转】Android LockScreen admin API sample code
- iOS开发中@property的属性weak nonatomic strong readonly等介绍
- zookeeper学习-2(如何使用zookeeper进行配置管理-java版本)
- 安全测试之缓冲区溢出(BO)