poj 3692 最大独立点集

来源:互联网 发布:php获取时间 编辑:程序博客网 时间:2024/05/29 19:14

题意:男同学间相互认识,女同学间相互认识,再给男女之间的认识关系,找一个集合,使选择的男女之间都相互认识

解法:如果以“认识”关系连线,在左右结合间都会连线,有背于二分图的含义,(线段的一个顶点在左集合,一个在右集合),所以我们可以以“不认识”关系连线,这样就得到了两个合理的集合,以给出的信息补集连线~


最大独立点集=定点数(|x+y|)-最大匹配数

/*----------------------------------   Love is more than a word.   It says so much.   When I see these four letters,   I almost feel your touch.   This is only happened since   I fell in love with you.   Why this word does this,   I haven't got a clue.                   To My Goddess                          CY----------------------------------*/#include<iostream>#include<cstring>#include<algorithm>#include<cstdlib>#include<vector>#include<cmath>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<map>#include <stdio.h>#include <queue>#define maxn 250+5#define ull unsigned long long #define ll long long#define reP(i,n) for(i=1;i<=n;i++) #define REP(i,a,b) for(i=a;i<=b;i++)  #define rep(i,n) for(i=0;i<n;i++)#define cle(a) memset(a,0,sizeof(a)) #define clehead(a) rep(i,maxn)a[i]=-1/*  The time of story :  **  while(1)    {         once upon a time,         there was a mountain,         on top of which there was a temple,         in which there was an old monk and a little monk.         Old monk was telling stories inside the temple.         What was he talking about?  **  }   ÎûÎû   (*^__^*)*/#define sci(a) scanf("%d",&a) #define scd(a) scanf("%lf",&a)  #define pri(a) printf("%d",a)   #define prie(a) printf("%d\n",a)    #define prd(a)  printf("%lf",a)     #define prde(a) printf("%lf\n",a)      #define pre printf("\n")#define LL(x) x<<1 #define RR(x) x<<|1#define pb push_back#define mod 90001#define PI 3.141592657const ull INF = 1LL << 61;const int inf =   int(1e5)+10;const double eps=1e-5;using namespace std;struct node{   int u,v,w;   int next;};bool cmp(int a,int b){    return a>b;}bool bmap[maxn][maxn];bool bmark[10000];int nx,ny;int cx[10000];int cy[10000];int m,g,b;int findpath(int u){    int i,j,k;    rep(i,ny){        if(bmap[u][i]&&!bmark[i]){            bmark[i]=1;            if(cy[i]==-1||findpath(cy[i]))            {                cy[i]=u;                cx[u]=i;                return 1;            }        }    }    return 0;}int maxmatch(){    int i,j,k;    int res(0);    rep(i,nx)cx[i]=-1;    rep(j,ny)cy[j]=-1;    rep(i,nx){       if(cx[i]==-1){         rep(j,ny)bmark[j]=0;         res+=findpath(i);       }    }    return res;}int main(){    freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    int T=0;    while(cin>>g>>b>>m)    {        if(m+g+b==0)break;        int i,j,k;        memset(bmap,true,sizeof(bmap));        nx=g,ny=b;        rep(i,m)        {            int x,y;            cin>>x>>y;            bmap[x-1][y-1]=false;        }        printf("Case %d: ",++T);        cout<<nx+ny-maxmatch()<<endl;    }    return 0;}


0 0
原创粉丝点击