LightOJ1149 :Factors and Multiples

时间限制:2000MS    内存限制:32768KByte   64位IO格式:%lld & %llu
描述

You will be given two sets of integers. Let's call them set Aand set B. Set A contains n elements and set Bcontains 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 k2in the range [0, m].

You have to find the value of (k1 + k2)such that (k1 + k2) is as low as possible. Pis 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 Bis {6, 7, 8, 9}. By removing 2 and 3 from A and 8from 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 setA and one from set B).

输入

Input starts with an integer T (≤ 50), denoting the number of test cases.

The first line of each case starts with an integer nfollowed by n positive integers. The second line starts with mfollowed 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 32bit signed integer.

输出

For each case of input, print the case number and the result.

样例输入

2

4 2 3 4 5

4 6 7 8 9

3 100 200 300

1 150

样例输出

Case 1: 3

Case 2: 0

提示
 
题目来源
Problem Setter: Sohel Hafiz
Special Thanks: Jane Alam Jan

唉...已经不想说话了...后续再补...

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#define ll long long using namespace std; const int N = ;
int head[N],total,visit[N];
int link[N]; struct nodes
{
int e,next;
} Edge[N]; void add(int x,int y)
{
Edge[total].e = y;
Edge[total].next = head[x];
head[x] = total++;
} int dfs(int f)
{
for(int i = head[f]; i != -; i = Edge[i].next)
{
int s = Edge[i].e;
if(visit[s]) continue;
visit[s] = ;
if(link[s] == - || dfs(link[s]))
{
link[s] = f ;
return ;
}
}
return ;
} void init()
{
total = ;
memset(head,-,sizeof(head));
memset(link,-,sizeof(link));
} int main(void)
{
int t,a[],b[];
int i,j,cnt1 = ;
cin>>t;
while(t--)
{
init();
int m,n;
cin>>m;
for(i = ; i < m; i++)
{
scanf("%d",&a[i]);
}
cin>>n;
for(i = ; i < n; i++)
{
scanf("%d",&b[i]);
}
for(i = ; i < m; i++)
for(j = ; j < n; j++)
if(b[j] % a[i] == )
add(i,m+j);
int cnt;
for(cnt = ,i = ; i < m+n; i++)
{
memset(visit,,sizeof(visit));
if(dfs(i))
cnt++;
}
printf("Case %d: %d\n",cnt1++,cnt);
} return ;
}

light oj 1149 Factors and Multiples(二分匹配)的更多相关文章

  1. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集

    m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...

  2. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  3. (LightOJ 1149) Factors and Multiples

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

  4. Timus OJ 1997 Those are not the droids you're looking for (二分匹配)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997 这个星球上有两种人,一种进酒吧至少玩a小时,另一种进酒吧最多玩b小时. 下面n行是 ...

  5. Factors and Multiples

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

  6. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

  7. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  8. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  9. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

随机推荐

  1. Python+Selenium基础入门及实践

    Python+Selenium基础入门及实践 32018.08.29 11:21:52字数 3220阅读 23422 一.Selenium+Python环境搭建及配置 1.1 selenium 介绍 ...

  2. 数组(Array)与 字符串(String)公用的属性与方法

    数组与字符串都有很多方法,有一些方法是公用的,在这里就将数组与字符串公用的方法提取出来,方便大家的记忆 1. length 可通过str.length与arr.length分别取到字符串与数组的长度: ...

  3. django-rest-framework-jwt的使用

    一简介 JWT 是一个开放标准(RFC 7519),它定义了一种用于简洁,自包含的用于通信双方之间以 JSON 对象的形式安全传递信息的方法.该信息可以被验证和信任,因为它是数字签名的.JWTS可以使 ...

  4. springboot下slf4j配置

    我们在引用的时候直接写 private static final Logger logger = LoggerFactory.getLogger(XXXServiceImpl.class); log. ...

  5. IDEA如何像Eclipse打开多个项目?

    简述: 不能采用open方式,得采用 import module方式 (多个项目,可以不再同一个根目录下,真正的类似eclipse方式打开多个项目) 具体操作步骤: 1.选择一个maven项目,右键选 ...

  6. Spring MVC(六)--通过URL传递参数

    URL传递参数时,格式是类似这样的,/param/urlParam/4/test,其中4和test都是参数,这就是所谓的Restful风格,Spring MVC中通过注解@RequestMapping ...

  7. OS -- (python)文件和目录操作方法大全

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法.1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()2.返回指定目录下的所有文件和目 ...

  8. centos7 yum 安装tomcat7

    查看yum中tomcat信息 yum info tomcat 安装 yum install tomcat 安装管理界面 yum install tomcat-webapps tomcat-admin- ...

  9. oracle日志

    UTL_FILE.FOPEN(location in varchar2, filename in varchar2, open_mode in varchar2) return FILE_TYPE; ...

  10. vue 学习 一

    1.实例: var vm = new Vue({ el: '#example', data: { a:1 }, created: function () { // `this` 指向 vm 实例 co ...