题意:有G个女生,B个男生,所有的女生都互相认识,所有的男生都互相认识,还有N对男女,他们互相认识。

问从中选出最多的人数,是的他们全部互相认识。

思路:这道题的构图很巧妙,对于他的补图构图,对于所有互相认识的人,我们置Map[i][j] = 0 ,那么不认识的人置为1.

因为最大独立集中所有的点相互都没有边,即他们之间互相都认识,所以这道题就转化成了求最大独立集。

最大独立集=点数-最大匹配。

CODE:

#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Max 2505
#define FI first
#define SE second
#define ll long long
#define PI acos(-1.0)
#define inf 0x3fffffff
#define LL(x) ( x << 1 )
#define bug puts("here")
#define PII pair<int,int>
#define RR(x) ( x << 1 | 1 )
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
using namespace std; int G , B , N ;
int Map[444][444] ;
bool vis[444] ;
int link[444] ;
bool find(int now){
for (int i = G + 1 ; i <= G + B ; i ++ ){
if(Map[now][i] && !vis[i]){
vis[i] = 1 ;
if(link[i] == -1 || find(link[i])){
link[i] = now ;return 1 ;
}
}
}
return 0 ;
}
int main() {
int ca = 0 ;
while(cin >> G >> B >> N ,(G + B + N)){
mem(Map ,-1) ;
mem(link ,-1) ;
for (int i = 0 ; i < N ; i ++ ){
int s , t ; scanf("%d%d",&s,&t) ;
Map[s][t + G] = 0 ;
// Map[t + G][s] = 0 ;
}
int ans = 0 ;
for (int i = 1 ; i <= G ; i ++ ){
mem(vis ,0) ;
ans += find(i) ;
}
printf("Case %d: %d\n",++ ca ,G + B - ans) ;
}
return 0;
}

POJ 3692 最大独立集的更多相关文章

  1. POJ 3692 Kindergarten(最大独立集)

    [题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相 ...

  2. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  3. poj 3692 Kindergarten (最大独立集之逆匹配)

    Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and al ...

  4. POJ 3692 Kindergarten(二分图最大独立集)

    题意: 有G个女孩,B个男孩.女孩彼此互相认识,男孩也彼此互相认识.有M对男孩和女孩是认识的.分别是(g1,b1),.....(gm,bm). 现在老师要在这G+B个小孩中挑出一些人,条件是这些人都互 ...

  5. POJ 3692 Kindergarten (二分图 最大团)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 Desc ...

  6. POJ 3692 Kindergarten(最大团问题)

    题目链接:http://poj.org/problem?id=3692 Description In a kindergarten, there are a lot of kids. All girl ...

  7. POJ 3692:Kindergarten(最大的使命)

    id=3692">Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Ac ...

  8. POJ 3692

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4787   Accepted: 2326 Desc ...

  9. poj 3692 二分图最大匹配

    思路: 如果我们将认识的建边,求最大独立集就是互相不认识的人数.那么我们反过来,将不认识的建图,求最大独立集就是互相认识的人数. #include<cstdio> #include< ...

随机推荐

  1. bzoj1196:[Hnoi2010]chorus 合唱队

    这数据范围明显的区间dp啊...然而据说二维会wa...那就写三维把... #include<cstdio> #include<cstring> #include<cct ...

  2. apache开源项目--ZooKeeper

    ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂易出错的关键服务 ...

  3. (3)java棧

    java棧和函数调用的关系图 [名词解释]--->java棧是一块线程的私有空间--->java的棧是先进后出的数据结构.函数返回,则该函数的棧帧被弹出.--->一个函数对应一个棧帧 ...

  4. Spring AOP--基于XML文件的配置

    Spring AOP的配置可以基于注解,也可以基于XML文件.前面几篇都是使用注解的方式.下面介绍下使用XML文件如何配置 使用的测试类和切面类都类似.只需要属于AOP的注解去掉即可.下面是AOP的X ...

  5. 我的web小游戏【持续更新中】

    在谷歌浏览器中实测无问题.. 五子棋(双人对战):http://1.waymongame.sinaapp.com/wuziqi/wuziqi2.html 贪吃蛇:http://1.waymongame ...

  6. Java中调用参数是数组的存储过程

    Java中调用参数是数组的存储过程 1. 存储过程以及类型定义如下: --The array in oracle CREATE OR REPLACE TYPE idArray AS TABLE OF ...

  7. Print the numbers between 30 to 3000.

    Microsoft Interview Question Developer Program Engineers 看到一个题目比较有意思: Print the numbers between 30 t ...

  8. 【JMeter】JMeter完成一个java请求的压测

    先定义一下我说的remoteService:即远程调用服务,没有http的url.不对外提供或者对外提供有限的服务.具体视各公司的代码架构所定,比如有些公司为web工程,scf服务,db.scf即为服 ...

  9. [Tommas] 测试用例覆盖率(二)

    二.详细用例的设计 划分好了测试项,接着就是针对各个测试项,考虑具体的测试用例了.根据测试项的特点,测试用例的设计角度也有所不同.下面我们就来看看通常的功能点测试用例,该从哪些角度出发来进行设计: 1 ...

  10. Oracle学习网址

    Oracle Error Search: http://www.ora-error.com/ Oracle Database Error Message - Oracle Documentation: ...