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. python使用SAX解析xml

    python 标准库包含SAX解析器,SAX用事件驱动模型,通过在解析XML的过程中触发一个个的事件并调用用户定义的回调函数来处理XML文件 在python中使用sax方式处理xml要先引入xml.s ...

  2. SQL SERVER镜像配置,无法将 ALTER DATABASE 命令发送到远程服务器实例的解决办法

    环境:非域环境 因为是自动故障转移,需要加入见证,事务安全模式是,强安全FULL模式 做到最后一步的时候,可能会遇到 执行( ALTER DATABASE [mirrortest] SET WITNE ...

  3. MySql与MariaDB由来与历程

    MySQL数据库 MySQL数据库是一个关系型数据库管理系统,由瑞典MySQL AB公司开发.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这 ...

  4. php+redis,延迟任务 实现自动取消订单,自动完成订单

    简单定时任务解决方案:使用redis的keyspace notifications(键失效后通知事件) 需要注意此功能是在redis 2.8版本以后推出的,因此你服务器上的reids最少要是2.8版本 ...

  5. Linux centos7下php安装cphalcon扩展的方法

    说明: 操作系统:CentOS7 php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini 运行环境:LNMP ,PHP7 .安装 ...

  6. visual studio 2015下使用gcc调试linux c++开发环境搭建完整详解

    一直以来,相信绝大部分的开发都是windows/mac下做开发,尤其是非嵌入式和qt系的,而开源服务器程序绝大部分都是跑在Linux下,几乎就没有跑在windows下的.一直以来开发人员都是在wind ...

  7. Fedora 全局代理上网设置

    1.首先新建一个bash文件 vim /etc/profile.d/proxy.sh 加入以下内容 (有账号密码) export HTTP_PROXY="http://username:pa ...

  8. 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况

    在app.config中的configuration节内添加子节Startup,详细如下: <?xml version="1.0"?><configuration ...

  9. 从客户端(XXX)中检测到有潜在危险的Request.Form 值

    aspx 页面出现 [HttpRequestValidationException (0x80004005):从客户端(TextBox1="<?xml version="1. ...

  10. 4698: Sdoi2008 Sandy的卡片

    前言 总之这个东西说起来很麻烦就是了, 思路 差分合并+后缀数组+二分(dddl) 类似于那个bzoj1031的复制子串和那个poj1743的差分 来看个例子 3 5 1 2 3 4 5 4 1 1 ...