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. vc 获取窗口标题GetWindowText

    今天在写一个模块,具体功能是想时刻监控用户当前活动窗口,需要获取窗口标题以及其它相关信息,记得API GetWindowText就是用来做这个的,结果试了半天,有的获取成功了有的获取失败了,而且有关汉 ...

  2. python 请求测试环境的https接口地址报SSL错误验证,访问不了

    解决文案: response = requests.post(url, data=payload, json=None, headers=headers,verify=False)print(resp ...

  3. android Serializable 和 Parcelable 区别

      android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable. 一 序列化原因: 1.永久性保存对象,保存对象的字节序列到本地文件中:2.通过 ...

  4. Mac系统下安装Vue-cli详细步骤

    Vue-cli安装 因为是mac系统,所以和视频里老师讲的有些许不同. 1.首先打开终端 按照老师的操作,首先检查node版本 下面是我的操作 打开终端,输入命令 node -v 我去,找不到node ...

  5. 杂项-VOD:VOD(视频点播)

    ylbtech-杂项-VOD:VOD(视频点播) 视频点播是二十世纪90年代在国外发展起来的,英文称为“Video on Demand”,所以也称为“VOD”.顾名思义,就是根据观众的要求播放节目的视 ...

  6. GCC 参数详解

    转载出处:http://blog.csdn.net/yff1030/article/details/8592077 原文:http://www.cppblog.com/SEMAN/archive/20 ...

  7. 转:Linux 文件IO理解

    源地址http://blog.csdn.net/lonelyrains/article/details/6604851 linux文件IO操作有两套大类的操作方式:不带缓存的文件IO操作,带缓存的文件 ...

  8. 如何应用AxureRP做原型设计

    什么是原型呢?这个在之前介绍为什么需要进行原型设计当中有提到,原型是产品的最初形态,确认用户对产品界面和操作功能可用性的需求,高保真的原型接近于产品的最终形态,但仍只是原型.产品原型简单的说就是产品设 ...

  9. python 之 heapq (堆)

    堆的实现通过构造二叉堆,实为二叉树的一种:这种数据结构具有以下性质: 任意节点小于(或大于)它的后裔,最小元(或最大元)在堆的根上 堆总是一颗完整树.即除了最低层,其它层的节点都被元素填满,且最低层极 ...

  10. day72test

    目录 models模型类 路由配置 视图配置 序列化组件配置 基于ModelSerializer类,完成Car资源的单查,群查,单增接口 序列化:显示车名,车的颜色,车的价格,车的海报,车的品牌 反序 ...