Factors and Multiples
Time Limit: 2 second(s) Memory Limit: 32 MB

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 Ak1 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 4or 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

Output for Sample Input

2

4 2 3 4 5

4 6 7 8 9

3 100 200 300

1 150

Case 1: 3

Case 2: 0

题意:两个集合,删除元素使下一个集合没有上一个集合的倍数,问最少删除几个元素。匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~

是猪么

 #include<iostream>
#include<cstdio>
#include<cstring> using namespace std; #define N 110 int used[N], vis[N], n, m;
int maps[N][N];
int a[N], b[N]; int found(int x)
{
for(int i = ; i < m; i++)
{
if(maps[x][i] && !vis[i])
{
vis[i] = ;
if(used[i] == - || found(used[i]))
{
used[i] = x;
return true;
}
}
}
return false;
} int main()
{
int t, k = ; scanf("%d", &t); while(t--)
{
memset(used, -, sizeof(used));
memset(maps, , sizeof(maps)); scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%d", &a[i]);
scanf("%d", &m);
for(int j = ; j < m; j++)
scanf("%d", &b[j]);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
if(b[j] % a[i] == )
maps[i][j] = ;
int cou = ;
for(int i = ; i < n; i++)
{
memset(vis, , sizeof(vis));
if(found(i))
cou++;
}
printf("Case %d: %d\n", k++, cou);
}
return ;
}

好好的福利场被人家抢了~是不是傻,是不是猪,是不是~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是

Factors and Multiples的更多相关文章

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

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

  2. (LightOJ 1149) Factors and Multiples

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

  3. LightOJ--1149--Factors and Multiples(二分图好题)

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

  4. Multiples of 3 and 5

    #include<stdio.h> int main(void){ int n1, n2,n3; n1=333*(3+999)/2; n2=199*(5+995)/2; n3=66*(15 ...

  5. 【算法题】Multiples of 3 and 5

    Multiples of 3 and 5 原题 题意如下: 找出N以内的3和5的倍数的和. 思路 1.刚看到觉得好弱智,直接遍历一遍不就OK了吗?但是第2和第3个测试用例报了TLE,超时. 2.然后想 ...

  6. [CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字

    7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7. 这道题跟 ...

  7. 1096. Consecutive Factors (20)

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  8. 机器学习 —— 概率图模型(Homework: Factors)

    Talk is cheap, I show you the code 第一章的作业主要是关于PGM的因子操作.实际上,因子是整个概率图的核心.对于有向图而言,因子对应的是CPD(条件分布):对无向图而 ...

  9. ACM - ICPC World Finals 2013 D Factors

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 一个最基本的算数法则就是大于1的整数 ...

随机推荐

  1. python 设置开机启动脚本

    1.创建python_auto.bat的快捷方式,放入启动项: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\ ...

  2. 【MM系列】SAP MM中物料帐下修改物料的价格

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 物料帐下修改物料的价格   ...

  3. C#中拼音模糊匹配汉字智能搜索

    准备: 微软官方出了一个专用的汉字转拼音包Microsoft Visual Studio International Pack 1.0 SR1 首先到官网http://www.microsoft.co ...

  4. 第四周实验报告&实验总结

    试验报告2 写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类 ...

  5. levelDB SSTable-静态布局结构

    SSTable是Bigtable中至关重要的一块,对于LevelDB来说也是如此,对LevelDB的SSTable实现细节的了解也有助于了解Bigtable中一些实现细节.     本节内容主要讲述S ...

  6. Git-第N篇碰见的一些问题

    1.关于windows平台自动换行问题 warning: LF will be replaced by CRLF in readme.txt. The file will have its origi ...

  7. HDU 4014 Jimmy’s travel plan(图计数)

    Jimmy’s travel plan Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  8. JEECG 深度使用培训班 周六周日公开课(一期班)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhangdaiscott/article/details/25411023 广大技术爱好者:     ...

  9. JAVA一个文件写多个类

    JAVA一个文件写多个类,并且是同级类,需注意: 在一个.java文件中可以有多个同级类,  其修饰符只可以public/abstract/final/和无修饰符 public修饰的只能有一个,且必须 ...

  10. 身为一个小白,看到一篇值得看的文章。讲述小白学习python的6个方法。

    01. Python怎么学?   Python虽然号称非常简单,功能强大!但是再简单,它也是一门编程语言,任何一个编程语言都会包含: 内功,心法和招式,内功心法就是指的算法,数据结构: 招式就是任何一 ...