Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

Submit
Status

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

Problem Setter: Sohel Hafiz
Special Thanks: Jane Alam Jan



给了两个集合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(二分图好题)的更多相关文章

  1. light oj 1149 Factors and Multiples(二分匹配)

    LightOJ1149 :Factors and Multiples 时间限制:2000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 You w ...

  2. 【二分图裸题】poj1325机器调度

    题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者] ...

  3. HDU - 1054 Strategic Game (二分图匹配模板题)

    二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...

  4. POJ 3041 Asteroids(二分图模板题)

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  5. Factors and Multiples

    Factors and Multiples   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...

  6. (LightOJ 1149) Factors and Multiples

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1149 Description You will be given two sets o ...

  7. hdu1083二分图匹配模板题

    onsider a group of N students and P courses. Each student visits zero, one or more than one courses. ...

  8. 51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题

    题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左 ...

  9. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

随机推荐

  1. sleep()和wait()的区别

    1 sleep()方法,我们首先要知道该方法是属于Thread类中的.而wait()方法,则是属于Object类中的. 2 Thread.sleep和Object.wait都会暂停当前的线程,对于CP ...

  2. [转]浏览器缓存详解: expires, cache-control, last-modified, etag详细说明

    最近在对CDN进行优化,对浏览器缓存深入研究了一下,记录一下,方便后来者 画了一个草图: 每个状态的详细说明如下: 1.Last-Modified 在浏览器第一次请求某一个URL时,服务器端的返回状态 ...

  3. NetCore下获取项目文件路径

    我要获取的是doc/FPFile.xml 百度了一大堆就是找不到解决问题. 把属性更改为始终赋值, XmlDocument xdi = new XmlDocument(); xdi.Load((&qu ...

  4. Excel的用到的常规的技巧

    这几天在做各种发票的报表,好几百的数据当然离不开EXCel,自己又是个白班,就记录下啦! EXCEL 判断某一单元格值是否包含在某一列中 就在Excel的表格中加入这个函数:=IF(ISERROR(V ...

  5. PHP CURL的几种用法

    1.抓取无访问控制文件 <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost/mytest/ ...

  6. php知识点(基本上文档都有,只为方便记忆)

    类型转换 (unset)转换为NULL (binary) 转换和 b 前缀转换支持为 PHP 5.2.1 新增   转换二进制 隐藏php后缀名 AddType application/x-httpd ...

  7. 08--C++拷贝构造函数详解

    C++拷贝构造函数详解 一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: [c-sharp] view plain copy int a = 100; int b ...

  8. React Native - 使用Vibration API实现设备振动

    有时程序中需要实现这样的功能,当有重要的消息提醒时,我们会发出声音告知用户.而如果用户关闭了声音,那么就可以改用振动来提醒用户. 使用 React Native 提供的 Vibration API,我 ...

  9. 09 Django组件之用户认证组件

    没有学习Django认证组件之前使用装饰器方法 from django.shortcuts import render, HttpResponse, redirect from app01.MyFor ...

  10. python tips:小整数对象池与字符串intern

    本文为is同一性运算符的详细解释.is用于判断两个对象是否为同一个对象,具体来说是两个对象在内存中的位置是否相同. python为了提高效率,节省内存,在实现上大量使用了缓冲池技术和字符串intern ...