Kindergarten
传送门:http://poj.org/problem?id=3692
Language:
Kindergarten
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6831 Accepted: 3374
Description
In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.
Input
The input consists of multiple test cases. Each test case starts with a line containing three integers
G, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and
the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.
The last test case is followed by a line containing three zeros.
Output
For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.
Sample Input
2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0
Sample Output
Case 1: 3
Case 2: 4
Source
2008 Asia Hefei Regional Contest Online by USTC
【解析】
题意:女孩们都互相认识,男孩们也都互相认识。有些男孩女孩互相认识,选出人数最多的互相认识的团体。
解法:求二分图的最大独立集。
如果我们选出的这些人两两互相认识,说明在一个图中这些点两两之间有连线,我们怎样找到这样一个图呢。
我们利用二分图的性质,将不认识的人连线。求最大独立集。最大独立集就是这个集合中的所有点两两之间没有连线。
没有连线就是互相认识。
最大独立集=所有的顶点个数-最大匹配。
【code】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200+10
int map[N][N],match[N];
bool vis[N];
int x,y,g,b,m,cnt,tim;
bool path(int x)
{
for(int i=;i<=b;i++)
{
if(!vis[i]&&!map[x][i])
{
vis[i]=;
if(!match[i]||path(match[i]))
{
match[i]=x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d",&g,&b,&m)&&g&&b&&m)
{
cnt=;//*注意清0
tim++;
memset(match,,sizeof(match));
memset(map,,sizeof(map));
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=;
}
for(int i=;i<=g;i++)
{
memset(vis,,sizeof(vis));
if(path(i))
cnt++;
}
printf("Case %d: %d\n",tim,g+b-cnt);
}
return ;
}
Kindergarten的更多相关文章
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- codeforces 484D D. Kindergarten(dp)
题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- POJ3692 Kindergarten 【最大独立集】
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5317 Accepted: 2589 Desc ...
- poj 3692 Kindergarten (最大独立集之逆匹配)
Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...
- POJ 3692 Kindergarten (二分图 最大团)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5660 Accepted: 2756 Desc ...
- POJ 3692:Kindergarten(最大的使命)
id=3692">Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4920 Ac ...
- Kindergarten Counting Game - UVa494
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva494.html 题目描述 Kin ...
- POJ3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6882 Accepted: 3402 Desc ...
- POJ 3692 Kindergarten(最大团问题)
题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...
随机推荐
- hdu4063(圆与圆交+线段与圆交+最短路)
写几何题总是提心吊胆.精度问题真心吓人. 其实思路挺简单的一道题,真是什么算法和几何double搞到一块,心里就虚虚的. 思路:求出所有圆之间的交点,然后用这些交点跑一遍最短路就可以了. Aircra ...
- org.apache.poi3.1.7 Excle并发批量导入导出
org.apache.poi3.1.7 升级,需要修改设置方式: 1.org.apache.poi3.1.4 的设置单元格: XSSFCellStyle cellStyle = wb.createCe ...
- 九度OJ 1249:次小生成树 (次小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:203 解决:56 题目描述: 最小生成树大家都已经很了解,次小生成树就是图中构成的树的权值和第二小的树,此值也可能等于最小生成树的权值和,你 ...
- 测试站如何最快获取正式站的最新数据: ln -s
针对静态数据, 比如图片/js等文件, 测试站如何获取最新的呢? ln -s /alidata/www/mysite/uploads /alidata/www/mysite_test/uploads ...
- 【python】-- SQLAlchemy操作MySQL
ORM.SQLAchemy orm英文全称object relational mapping,就是对象映射关系程序,简单来说就是类似python这种面向对象的程序来说一切皆对象,但是使用的数据库却都是 ...
- 【译】Stackoverflow:Java Servlet 工作原理问答
导读 本文来自stackoverflow的问答,讨论了Java Servlet的工作机制,如何进行实例化.共享变量和多线程处理. 问题:Servlet 是如何工作的?Servlet 如何实例化.共享变 ...
- 我的Android进阶之旅------>Android二级ListView列表的实现
实现如下图所示的二级列表效果 首先是在布局文件中,布局两个ListView,代码如下: <LinearLayout xmlns:android="http://schemas.andr ...
- Django用ajax发送post请求时csrf拦截的解决方案
把下面的代码写在模版文件中就可以了, 注:不是js文件,是模版文件加载的执行的,所有写js里没效果 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf ...
- windows10下载
http://care.dlservice.microsoft.com/dl/download/F/5/7/F574727C-B145-4A7D-B85B-11C4E8DC894B/9841.0.14 ...
- struts2中的ModelDriven使用
http://www.cnblogs.com/Topless/archive/2012/01/17/2324980.html 例子都为struts2中的文档例子 JSP提交数据: <s:fo ...