Cat VS Dog

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)

Problem Description
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers dislike-animal must be a dog, and vice versa.
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
 
Input
The input file contains multiple test cases, for each case, the first line contains three integers N <= 100, M <= 100 and P <= 500.
Next P lines, each line contains a child's like-animal and dislike-animal, C for cat and D for dog. (See sample for details)
 
Output
For each case, output a single integer: the maximum number of happy children.
 
Sample Input
1 1 2
C1 D1
D1 C1

1 2 4
C1 D1
C1 D1
C1 D2
D2 C1

 
Sample Output
1
3

Hint

Case 2: Remove D1 and D2, that makes child 1, 2, 3 happy.

 
Source

题意:给你m只狗跟n只猫,p个人,每个人有一只喜欢和不喜欢的动物;

   可以选取一些动物,使得满足条件的人最多;

   满足条件:一个人的喜欢的动物在,并且不喜欢的动物不在;

思路:二分图匹配最大点独立集模型=所有人-最大匹配;

   把所有人的对立的关系连边;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-6
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e3+,M=1e6+,inf=1e9+;
const LL INF=5e17+,mod=1e9+; int n,m;
int mp[N][N];
int linker[N];
bool used[N];
bool dfs(int a)
{
for(int i=;i<n;i++)
if(mp[a][i]&&!used[i])
{
used[i]=true;
if(linker[i]==-||dfs(linker[i]))
{
linker[i]=a;
return true;
}
}
return false;
}
int hungary()
{
int result=;
memset(linker,-,sizeof(linker));
for(int i=;i<n;i++)
{
memset(used,,sizeof(used));
if(dfs(i)) result++;
}
return result;
}
string l[N],disl[N];
int main()
{
int c,d;
while(~scanf("%d%d%d",&c,&d,&n))
{
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
cin>>l[i]>>disl[i];
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(l[i]==disl[j]||disl[i]==l[j])
mp[i][j]=;
}
}
int cnt=hungary();
printf("%d\n",n-cnt/);
}
return ;
}

hdu 3829 Cat VS Dog 二分图匹配 最大点独立集的更多相关文章

  1. hdu 3829 Cat VS Dog 二分匹配 最大独立点集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从 ...

  2. HDU - 3829 Cat VS Dog (二分图最大独立集)

    题意:P个小朋友,每个人有喜欢的动物和讨厌的动物.留下喜欢的动物并且拿掉讨厌的动物,这个小朋友就会开心.问最多有几个小朋友能开心. 分析:对于每个动物来说,可能既有人喜欢又有人讨厌,那么这样的动物实际 ...

  3. HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配)

    HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...

  4. HDU 3829——Cat VS Dog——————【最大独立集】

    Cat VS Dog Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  5. hdu 2768 Cat vs. Dog (二分匹配)

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU 3829 Cat VS Dog (最大独立集)【二分图匹配】

    <题目链接> 题目大意: 动物园有n条狗.m头猫.p个小孩,每一个小孩有一个喜欢的动物和讨厌的动物.如今动物园要转移一些动物.假设一个小孩喜欢的动物在,不喜欢的动物不在,他就会happy. ...

  7. HDU 3829 - Cat VS Dog (二分图最大独立集)

    题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...

  8. HDU 3829 Cat VS Dog(最大独立集)

    题目大意: 有n只猫,有m只狗.现在有P个学生去参观动物园.每个孩子有喜欢的动物和不喜欢的动物.假如他喜欢猫那么他就一定不喜欢狗(反之亦然). 如果一个孩子喜欢一个动物,那么这个动物不会被移除,若是不 ...

  9. HDU 3829 Cat VS Dog

    题意: p个人  每一个人有喜欢和讨厌的动物  假设选出的动物中包括这个人喜欢的动物同一时候不包括他讨厌的动物那么这个人会开心  问  最多几个人开心 思路: 二分图最大独立集  利用人与人之间的冲突 ...

随机推荐

  1. Numpy 矩阵

    矩阵定义在NumPy中,矩阵是ndarray的子类,可以由专用的字符串格式来创建 1. 创建矩阵mat函数创建矩阵(mat函数创建矩阵时,若输入已为matrix或ndarray对象,则不会为它们创建副 ...

  2. [转载]C#中IndexOf的使用

    注:此方法无法找出目标字符串第二次.第三次等出现的位置. 具体代码如下所示: 1 2 3 4 5 var array=['REG','2018','2018'];   array.indexOf(‘R ...

  3. 大数据自学5-Python操作Hbase

    在Hue环境中本身是可以直接操作Hbase数据库的,但是公司的环境不知道什么原因一直提示"Api Error:timed out",进度条一直在跑,却显示不出表. 但是在CDH后台 ...

  4. AJAX异步请求,局部刷新

    AJAX异步请求,局部刷新 window.onload=function(){ //dom事件,页面加载完成执行如下函数 doGetObjects(); } function doGetObjects ...

  5. shell中test命令方法详解

    test命令用法.功能:检查文件和比较值 1)判断表达式 if test  (表达式为真) if test !表达式为假 test 表达式1 –a 表达式2                 两个表达式 ...

  6. svn钩子

    #!/bin/sh #修改为服务编码 export.UTF-8 #Set variable REPOS="$1" REV="$2" #svn安装脚本目录 SVN ...

  7. Differences Between Enterprise, Standard and Standard One Editions on Oracle 11.2 (Doc ID 1084132.1)

    标准版不允许并行.分区.闪回.各种缓存等大数据量必须特性,如此限制,oracle摆明了只卖企业版,买标准版不如mysql(如果不熟悉postgresql的话). Oracle企业版1 CPU 20w起 ...

  8. java jdbc->mycat->oracle SqlException异常中文信息乱码解决

    mycat字符集gbk oracle字符集gbk 原jdbc连接串: base.jdbc.url=jdbc:mysql://127.0.0.1:3306/XXX?useUnicode=true& ...

  9. python元组与购物车程序

    #Author:zww ''' 程序:购物车程序 需求: 1.启动程序后,让用户输入工资,然后打印呢商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否足够,够就直接扣款,不够 ...

  10. phpstorm官方教程

    https://confluence.jetbrains.com/pages/viewpage.action?pageId=15801728