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. 打开串口(COM)号大于9时报错

    使用CreateFile打开串口(COM)号大于9时报错,GetLastError()的值为2. 解决方法: // 把串口名称由 "COMN" 改为 "\\.\COMN& ...

  2. 用在 AMD64 上 aria2_1.33.1-1_amd64.deb 的下载页面

    用在 AMD64 上 aria2_1.33.1-1_amd64.deb 的下载页面 如果您正在运行 Ubuntu,请尽量使用像 aptitude 或者 synaptic 一样的软件包管理器,代替人工手 ...

  3. Android开发 ViewPager删除Item后,不会更新数据和View

    问题描述: 在使用ViewPager的适配器删除适配器里一个Item后依然会,而删除的这个item依然会保留缓存,适配器不会重新加载更新数据.如下代码: public class TReleaseCi ...

  4. mysql主从跳过错误

    mysql主从复制,经常会遇到错误而导致slave端复制中断,这个时候一般就需要人工干预,跳过错误才能继续 跳过错误有两种方式: 1.跳过指定数量的事务 mysql>stop slave;  m ...

  5. 异常处理记录: Servlet class X is not a javax.servlet.Servlet

    使用Maven的tomcat插件启动Web项目, 访问资源时, 发生如下异常: https://stackoverflow.com/questions/1036702/my-class-is-not- ...

  6. MAC地址获取,有线网卡与无线网卡、物理网卡与虚拟网卡的区分

    获取当前活跃状态的网卡MAC地址.物理地址 Wmic命令:Win32_NetworkAdapter和Win32_NetworkAdapterConfiguration. 其中cmd命令行执行: 1. ...

  7. 洛谷P3694 邦邦的大合唱

    题目背景 BanG Dream!里的所有偶像乐队要一起大合唱,不过在排队上出了一些问题. 题目描述 N个偶像排成一列,他们来自M个不同的乐队.每个团队至少有一个偶像. 现在要求重新安排队列,使来自同一 ...

  8. React项目开发经验汇总

    博客来源 小寒的博客   定义好全局配置信息 环境变量不要提取出来,配置信息提取出来 UI样式变量 定义好变量的作用不用多说 样式库建设 工具样式,复用性强的样式,这些class成为会是真个网站样式的 ...

  9. 你知道的和不知道的sass

    关于sass,大多数人的认识一个写css的工具而已 其实就是的 但是这个工具的威力你发挥了多少呢... 以下全部都是干货,希望你能用在自己的项目里 定义集合 我们通常是这么定义变量的 $warning ...

  10. lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(一) 简介

    一. 为什么这样构架 1. 系统高可用性 2. 系统可扩展性 3. 负载均衡能力 LVS+keepalived能很好的实现以上的要求,keepalived提供健康检查,故障转移,提高系统的可用性!采用 ...