题目链接:http://lightoj.com/volume_showproblem.php?problem=1149

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 {, , , } and set B is {, , , }. By removing and from A and from B, we get the sets {, } and {, , }. Here none of the integers , or is a multiple of or . So for this case the answer is (two from set A and one from set B). Input
Input starts with an integer T (≤ ), 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 [, ]. Each element of the two sets will fit in a bit signed integer. Output
For each case of input, print the case number and the result. Sample Input Sample Output
Case :
Case :

方法:二分匹配,求最大匹配数

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std; #define met(a,b) memset(a,b,sizeof(a))
#define ll long long
#define N 505
int Map[N][N],vis[N],used[N];
int a[N],b[N];
int n,m;
int han(int u)
{
for(int i=;i<=m;i++)
{
if(!vis[i] && Map[u][i])
{
vis[i]=;
if(!used[i] || han(used[i]))
{
used[i]=u;
return ;
}
}
}
return ;
}
int main()
{
int t,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);met(Map,);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d",&b[i]);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
if(b[j]%a[i]==)
Map[i][j]=;
}
met(used,);int sum=;
for(int i=;i<=n;i++)
{
met(vis,);
sum+=han(i);
} printf("Case %d: %d\n",con++,sum);
}
return ;
}

(LightOJ 1149) Factors and Multiples的更多相关文章

  1. Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)

    Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...

  2. Sigma Function (LightOJ - 1336)【简单数论】【算术基本定理】【思维】

    Sigma Function (LightOJ - 1336)[简单数论][算术基本定理][思维] 标签: 入门讲座题解 数论 题目描述 Sigma function is an interestin ...

  3. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

  4. (最长公共子序列+推导)Love Calculator (lightOJ 1013)

    http://www.lightoj.com/volume_showproblem.php?problem=1013   Yes, you are developing a 'Love calcula ...

  5. (状压) Marriage Ceremonies (lightOJ 1011)

    http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes mar ...

  6. A New Function(LightOJ 1098)积性函数前缀和的应用

    题意:要求对于1~n,每个数的约数(不包括1和其本身)的和. 题解:由于题目数据有2*10^9之大,因而不能直接暴力.需要考虑积性函数的特性,由于必定有重复的约数出现,因而可以对重复约数所在的区间进行 ...

  7. Harmonic Number (LightOJ 1234)(调和级数 或者 区块储存答案)

    题解:隔一段数字存一个答案,在查询时,只要找到距离n最近而且小于n的存答案值,再把剩余的暴力跑一遍就可以. #include <bits/stdc++.h> using namespace ...

  8. (LightOJ 1030)期望dp

    You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...

  9. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

随机推荐

  1. .NET常用操作小知识

    一..NET截取指定长度汉字超出部分以“.....”表示 /// <summary> /// 将指定字符串按指定长度进行剪切, /// </summary> /// <p ...

  2. cocos2d-x Menu、MenuItem

    转自:http://codingnow.cn/cocos2d-x/832.html 学习cocos2d-x中的菜单主要需要了解:菜单(CCMenu)和菜单项(CCMenuItem)以及CCMenuIt ...

  3. 【转】phpmyadmin万能密码漏洞

    影响版本:2.11.3 / 2.11.4 利用方法:用户名处写入‘localhost’@'@”则登录成功. (注意全部是英文标点符号,最后一个为英文双引号) 附上几个php爆绝对路径的办法: phpM ...

  4. JavaScript学习笔记之下拉选择框的操作

    对于下拉框的操作十分繁多,这几天项目须要就总结一下 一.动态构建option 有时候我们须要动态构建下拉选择框里面的值,这里我们就要用到 var varItem = new Option(" ...

  5. XMLHTTP使用具体解释

    XMLHTTP对象是Microsoft的MSXML开发包中带的一个用HTTP,XML协议訪问web资源的对象. 从MSXML3.0開始出现. 它在AJAX技术中主要用来从其它网络资源获取信息,然后由j ...

  6. Compiling aSmack

    For a recent mobile project we used XMPP. It worked really well and I’m keen to use it again. But, i ...

  7. java nio 抛出NonWritableChannelException异常

    抛出异常的代码在此处: MappedByteBuffer buffer = channel.map(MapMode.READ_WRITE, 0, avalible); 其中channel是一个file ...

  8. [React Fundamentals] Component Lifecycle - Mounting Basics

    React components have a lifecycle, and you are able to access specific phases of that lifecycle. Thi ...

  9. Android ListView快速定位(四)

    方法四: 添加一个EditText,作为搜索框 + Filter 其实这个不算第四个方法,因为与第二个一样,主要是实现Filter. 但是对于EditText的监听,我以前也没有写过,所以也记录一下. ...

  10. 文件和目录之chown、fchown和lchown函数

    下面几个chown函数可用于更改文件的用户ID和组ID. #include <unistd.h> int chown( const char *pathname, uid_t owner, ...