light oj 1149 Factors and Multiples(二分匹配)
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 HafizSpecial 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(二分匹配)的更多相关文章
- Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- (LightOJ 1149) Factors and Multiples
题目链接:http://lightoj.com/volume_showproblem.php?problem=1149 Description You will be given two sets o ...
- 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行是 ...
- Factors and Multiples
Factors and Multiples PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- Jan's light oj 01--二分搜索篇
碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
随机推荐
- Luogu P2822 组合数问题(前缀和)
P2822 组合数问题 题意 题目描述 组合数\(C_n^m\)表示的是从\(n\)个物品中选出\(m\)个物品的方案数.举个例子,从\((1,2,3)\)三个物品中选择两个物品可以有\((1,2), ...
- 搭建react的vw架构时候报 Cannot load preset "advanced".
原版的报错如下 Administrator@DESKTOP-EHCTIOR MINGW64 /e/821box/react-vw-layout (master) $ yarn start yarn r ...
- Codeforces Parking Lot
http://codeforces.com/problemset/problem/630/I 简单的排列组合,推式子技巧:举一个小样例,看着推,别抽象着推,容易错 #include <iostr ...
- EazyUI_Datagrid_行内编辑(editor)的combobox下拉框带图片
1.业务需求: 商品的明细列表里面下拉框需要 [图片+文字 ] 显示 2.我们使用的是EazyUI,而我比较懒,不习惯用拼接html来显示列表页面,使用的是eazyui的数据网格(datagrid) ...
- 如何玩转跨库Join?跨数据库实例查询应用实践
背景 随着业务复杂程度的提高.数据规模的增长,越来越多的公司选择对其在线业务数据库进行垂直或水平拆分,甚至选择不同的数据库类型以满足其业务需求.原本在同一数据库实例里就能实现的SQL查询,现在需要跨多 ...
- 前端-form表单与CSS
目录 form表单 表单属性 label标签 input标签 select 下拉框标签 textarea多行文本 提交 Flask 结合form表单 初探 CSS介绍以及基本选择器 基本选择器 组合选 ...
- axios请求头几种区别:application/x-www-form-urlencoded
今天小伙伴问我们项目axios默认请求头是application/x-www-form-urlencoded;charset=UTF-8, 现在有个后端接口要求请求头方式为application/js ...
- React弹窗组件
原文地址 小寒的博客 这里的弹窗泛指所有的弹出组件,这些组件不受页面其他UI布局影响,处于DOM结构的顶层,绝对定位在body元素下. 这个特殊性也给它的开发提出了特殊的要求. react新版本中的c ...
- Java-Shiro:Shiro
ylbtech-Java-Shiro:Shiro 1.返回顶部 1. Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API, ...
- Android基础控件DatePicker的使用
1.简介 DatePicker日期选择器,自带spinner和calendar两种模式,相关属性: android:calendarTextColor : 日历列表的文本的颜色 android:cal ...