POJ 2289 多重二分匹配+二分 模板
题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值
下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说可以用DINIC跑二分图可以得到sqrt(v)*E的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int maxn=100000; int n,m,k;
int mp[1005][505],link[505][1005],num[505],vis[505];
char s[20],c; bool find_path(int u,int mid)
{
for(int v=0;v<m;v++)
if(mp[u][v]&&!vis[v])
{
vis[v]=1;
if(num[v]<mid)
{
link[v][++num[v]]=u;
return true;
}
for(int i=1;i<=num[v];i++)
if(find_path(link[v][i],mid))
{
link[v][i]=u;
return true;
}
//vis[v]=0;这个地方不能将vis[v]清0,否则将多次重复计算,从而超时
//事实上只要右边的点检查过一次无法再匹配了,以后就都不行了
}
return false;
} bool ok(int mid)
{
MM(link,0);
MM(num,0);
for(int u=0;u<n;u++)
{
MM(vis,0);
if(!find_path(u,mid))
return false;
}
return true;
} int main()
{
while(~scanf("%d %d",&n,&m)&&(n||m))
{
MM(mp,0); for(int i=0;i<n;i++)
{
scanf("%s",s);
while(~scanf("%c",&c))
{
if(c=='\n') break;
scanf("%d",&k);
mp[i][k]=1;
}
} int l=-1,r=n+1;
while(r-l>1)
{
int mid=(l+r)>>1;
if(ok(mid)) r=mid;
else l=mid;
}
printf("%d\n",r);
}
return 0;
}
POJ 2289 多重二分匹配+二分 模板的更多相关文章
- POJ-1274The Perfect Stall,二分匹配裸模板题
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23313 Accepted: 103 ...
- poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...
- fafu 1568 Matrix(二分匹配+二分)
Description: You are given a matrix which <= n <= m <= ). You are supposed to choose n el ...
- ZOJ 3156 Taxi (二分匹配+二分查找)
题目链接:Taxi Taxi Time Limit: 1 Second Memory Limit: 32768 KB As we all know, it often rains sudde ...
- zoj 2362 Beloved Sons【二分匹配】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...
- POJ 2289 Jamie's Contact Groups & POJ3189 Steady Cow Assignment
这两道题目都是多重二分匹配+枚举的做法,或者可以用网络流,实际上二分匹配也就实质是网络流,通过枚举区间,然后建立相应的图,判断该区间是否符合要求,并进一步缩小范围,直到求出解.不同之处在对是否满足条件 ...
- Poj 2289 Jamie's Contact Groups (二分+二分图多重匹配)
题目链接: Poj 2289 Jamie's Contact Groups 题目描述: 给出n个人的名单和每个人可以被分到的组,问将n个人分到m个组内,并且人数最多的组人数要尽量少,问人数最多的组有多 ...
- POJ 2289(多重匹配+二分)
POJ 2289(多重匹配+二分) 把n个人,分到m个组中.题目给出每一个人可以被分到的那些组.要求分配完毕后,最大的那一个组的人数最小. 用二分查找来枚举. #include<iostream ...
- POJ 2289——Jamie's Contact Groups——————【多重匹配、二分枚举匹配次数】
Jamie's Contact Groups Time Limit:7000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
随机推荐
- lua基础学习(六)
一.lua协同程序coroutine 1.什么是协同(coroutine)?Lua 协同程序(coroutine)与线程比较类似:拥有独立的堆栈,独立的局部变量,独立的指令指针,同时又与其它协同程序共 ...
- vps分区 挂载wdcp 的/www目录大小调整或增加分区/硬盘的方法
http://www.wdlinux.cn/bbs/viewthread.php?tid=3574&highlight=%B7%D6%C7%F8 http://www.80vps.com/ne ...
- 解决reportNG中文乱码(转:http://www.it610.com/article/3626590.htm)
1.下载reportng源码 git clone https://github.com/dwdyer/reportng.git 2.修改AbstractReporter.java ...
- 【Linux 网络编程】TCP/IP四层模型
应用层.传输层.网络层.链路层 链路层:常用协议 ARP(将物理地址转化为IP地址) RARP(将IP地址转换为物理地址) 网络层(IP层):重要协议ICMP IP IGMP 传输层:重要的协议TCP ...
- JackRabbit的来源
题记 写这系列有点老调重弹的味道,比如ahuaxuan已经在他的博客里对于JackRabbit 1.0做了很详细的阐述.之所以再写,是因为JCR推出了JCR 2.0,个人觉得有必要将一些新的特性再罗列 ...
- adb 设置安卓连接wifi
一. 修改wpa_supplicant.conf文件 1.1. 获得root权限 adb root 1.2. 将wpa_supplicant.conf拷贝到你的电脑 adb pull /data/mi ...
- jquery html select 清空保留第一项
<select id="a"> <option>1</option> <option>2</option> <op ...
- 让图片img标签上下左右居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [WPF]BringIntoView
1.在scrollview 中的frameworkelement可以使用 FE.BringIntoView(); 滚动到此控件. 2.该 方法能一个重载 Bottom.BringIntoView(ne ...
- 服务安全之:JWT
JWT是JSON Web Tokens的缩写.既然叫JSON Web Tokens,所以JWT Tokens中真正包含的是多个JSON对象.为什么是多个JSON对象呢?因为SWT Token实际 ...