LightOJ--1149--Factors and Multiples(二分图好题)
| Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
Description
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
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(二分图好题)的更多相关文章
- light oj 1149 Factors and Multiples(二分匹配)
LightOJ1149 :Factors and Multiples 时间限制:2000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 You w ...
- 【二分图裸题】poj1325机器调度
题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者] ...
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- POJ 3041 Asteroids(二分图模板题)
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- Factors and Multiples
Factors and Multiples PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- (LightOJ 1149) Factors and Multiples
题目链接:http://lightoj.com/volume_showproblem.php?problem=1149 Description You will be given two sets o ...
- hdu1083二分图匹配模板题
onsider a group of N students and P courses. Each student visits zero, one or more than one courses. ...
- 51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题
题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左 ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
随机推荐
- javascript 核心概念(1)-数据类型
语法 (1)到现在为止,大多数浏览器也还是支持到ECMAScript 第三版的标准. 核心概念就是一个语言的基本工作原理,涉及语法,操作符,数据类型. (2)javascript的一切--变量,函数名 ...
- 域名转让(bcd.cn,tjcpda.com,jscpda.com,fjcpda.com)
因本人工作有所调整,现对所拥有的域名全部转让,有需要者请与我联系,谢谢. bcd.cn tjcpda.com jscpda.com fjcpda.com 联系方式: QQ:1181608198 Ema ...
- android.system.ErrnoException: open failed: ENOENT (No such file or directory) 07-19 20:27:45.011 66
在操作安卓版本23+的文件读取时,不仅要在maniests中声明,还要在代码中动态声明: ; private static String[] PERMISSIONS_STORAGE = { Manif ...
- 2星|《工业X.0》:物联网的资料汇编
工业X.0:实现工业领域数字价值 看完比较失望,没有看到新的观点想法.基本算是物联网的资料汇编.总体评价2星. 以下是书中一些内容的摘抄: 1:例如,埃森哲为其员工开发了一个用例,用增强现实技术解决实 ...
- kafka概述与下一代消息队列
常用的消息中间件 消息中间件是当前处理大数据的一个非常重要的组件,用来解决应用解耦.异步通信.流量控制等问题,从而构建一个高效.灵活.消息同步和异步传输处理.存储转发.可伸缩和最终一致性的稳定系统.目 ...
- wget 批量下载网站目录下的文件
执行如下命令就会自动下载 http://www.iyunwei.com/docs/ 下面的所有文件: wget -nd -r -l1 --no-parent http://www.iyunwei.co ...
- python 疑难杂症
1.getpass模块 :Pycharm不支持getpass模块,使用terminal可运行,但是getpass中文提示显示乱码?
- eas启动服务器时非法组件
EAS实例启动报系统中存在非法组件,实例启动失败: 组件检查机制,要求除了 $EAS_HOME eas\server\lib: $EAS_HOME \eas\server\deploy\files ...
- 【剑指Offer】12、数值的整数次方
题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 解题思路: 本题看似比较简单,是一个简单的指数运算,但需要完 ...
- Hzoi 2018.2.11多边形 区间DP
给定一个由N个顶点构成的多边形,每个顶点被赋予一个整数值,而每条边则被赋予一个符号:+(加法运算)或者*(乘法运算),所有边依次用整数1到N标识. 一个多边形的图形表示 首次移动,允许将某条边删除: ...