poj Kindergarten

Kindergarten

又是一道自己没思考出来的题 !!!!!

还是老样子,题目去我拉的专题里有。

题目:

给出G给女孩,B给男孩。女孩之间是相互认识的,男孩之间也是相互认识的。现在题目中给出M对男女间会相互认识的关系普,要你计算出男女之间两两都认识的最大人数。

算法:

一开始看到以为是最大团。囧。后来越想越不对啊。后来看到别人说是求解补图的问题。太深奥了。为了求出满足题目的条件,则要转换成最大独立集来求解。

证明如下:

最大独立集是所有点任意两点间都没有连边。

最大团要求:任意两点间都有连边。

补图中:任意两点间都没有连边,意味着原图中任意两点间都有连边。

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN = 200 + 10;
int G[MAXN][MAXN];
int match[MAXN];
bool used[MAXN];

int g,b,m;

bool dfs(int u){
   for(int i = 1;i <= b;++i){
       if(!used[i]&&G[u][i]){
           used[i] = 1;
           if(match[i] == -1||dfs(match[i])){
              match[i] = u;
              return true;
           }
       }
   }
   return false;
}

void solve(){
    int res = 0;
    memset(match,-1,sizeof(match));
    for(int i = 1;i <= g;++i){
        memset(used,0,sizeof(used));
        if(dfs(i))res++;
    }
    printf("%d\n",g + b - res);
}

int main()
{
    //freopen("Input.txt","r",stdin);

    int kase = 1;
    while(scanf("%d%d%d",&g,&b,&m),(g||m||b)){
        for(int i = 0;i <= g;++i){
            fill(G[i],G[i] + 1 + b,1);
        }

        int x,y;
        for(int i = 0;i < m;++i){
            scanf("%d%d",&x,&y);
            G[x][y] = 0;
        }
        printf("Case %d: ",kase++);
        solve();
    }
    return 0;
}
时间: 2024-10-12 11:56:39

poj Kindergarten的相关文章

POJ 3692 Kindergarten (二分图 最大团)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5660   Accepted: 2756 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

POJ 3692:Kindergarten(最大团)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4920   Accepted: 2399 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

poj 3692 Kindergarten (最大团模板题)

题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5156   Accepted: 2512 Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know e

POJ 3692 Kindergarten【最大点独立集】

大意: 有n个boy  m个girle   boy之间相互了解  girle之间相互了解 又告诉你一些boy和girle之间相互了解的关系 问最多选出多少人使其相互之间相互了解 分析: 左集合boy  右girle 若boy与girle相互不了解则建一条边,这样,有边相连的便是不相互了解的 那么最大点独立便是选取一些点使其相互之间没有边相连也就是相互了解的 note: 由于左右集合不相等所以选取nm中的较大的作为点的个数 最后结果为2 * max(n, m) - 最大匹配 代码: 1 #incl

poj 3692 Kindergarten (最大独立集)

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 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

POJ 3692 Kindergarten(最大团问题)

题目链接:http://poj.org/problem?id=3692 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 pi

POJ 3692 Kindergarten(最大独立集)

[题目链接] http://poj.org/problem?id=3692 [题目大意] 男生相互之间都认识,女生相互之间也都认识, 一些男生和一些女生相互之间也认识,求找出最多的人参加派对, 他们相互之间都认识 [题解] 我们建认识图的反图,将相互之间不认识的连线, 那么问题转化为求这个图的最大独立集, 最大独立集答案为总点数减去最大匹配. [代码] #include <cstdio> #include <cstring> using namespace std; const i

poj 3692 Kindergarten

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6956   Accepted: 3436 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

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

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 n