Cat VS Dog

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2046    Accepted Submission(s): 719

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
2011 Multi-University Training Contest 1 - Host by HNU

Recommend
xubiao

分析:如果两个小朋友满足以下情况:1.A喜欢的是B讨厌的.2.A讨厌的是B喜欢的.此时这两个小朋友肯定不能同时高兴,那么就在他们之间连一条边.只要求出此图的最大独立集即可.

#include<stdio.h>
#include<string.h>
int N,M,P;
int match[];
bool visit[],G[][];
char sl[],sd[];
int pl[],pd[];
bool DFS(int k)
{
for (int i=;i<=P;i++)
if (G[k][i] && !visit[i])
{
visit[i]=;
int t=match[i];
match[i]=k;
if (t==- || DFS(t)) return true;
match[i]=t;
}
return false;
}
int Max_match()
{
int ans=;
memset(match,-,sizeof(match));
for (int i=;i<=P;i++)
{
memset(visit,,sizeof(visit));
if (DFS(i)) ans++;
}
return ans;
}
int main()
{
char tmp;
int i,j;
while (scanf("%d%d%d",&N,&M,&P)!=EOF)
{
tmp=getchar();
for (i=;i<=P;i++)
{
scanf("%c%d %c%d",&sl[i],&pl[i],&sd[i],&pd[i]);
tmp=getchar();
}
memset(G,,sizeof(G));
for (i=;i<=P;i++)
for (j=;j<=P;j++)
if (i!=j)
{
if (pl[i]==pd[j] && sl[i]==sd[j]) G[i][j]=;
if (pd[i]==pl[j] && sd[i]==sl[j]) G[i][j]=;
}
printf("%d\n",P-Max_match()/);
}
return ;
}

Cat VS Dog的更多相关文章

  1. HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)

    题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...

  2. (hdu step 6.3.7)Cat vs. Dog(当施工方规则:建边当观众和其他观众最喜爱的东西冲突,求最大独立集)

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

  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: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  5. Hdu3829 Cat VS Dog(最大独立点集)

    Cat VS Dog Problem Description The zoo have N cats and M dogs, today there are P children visiting t ...

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

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

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

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

  8. HDU3829:Cat VS Dog(最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

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

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

随机推荐

  1. 程序员必读:Linux内存管理剖析

    现在的服务器大部分都是运行在Linux上面的,所以作为一个程序员有必要简单地了解一下系统是如何运行的. 对于内存部分需要知道: 地址映射 内存管理的方式 缺页异常 先来看一些基本的知识,在进程看来,内 ...

  2. pure MVC框架目标与好处

    框架一瞥 PureMVC是一个为创建基于经典MVC元设计模式应用的轻量级框架. 此框架是开源且免费的,已经被AS2,AS3,Java,C#以及其他流行语言所实现.这也允许在多样的平台上开发,包括: l ...

  3. Can't connect to local MySQL Server throught socket '/var/run/mysqld/mysqld.sock'(2)

    www.iwangzheng.com 由于之前调整了/etc/mysql/my.cnf试图修复数据库不能存中文的问题,这个问题没解决,以至于数据库连接不上了. tail -f /var/log/mys ...

  4. :( Call to a member function Table() on a non-object 错误位置

    :( Call to a member function Table() on a non-object 错误位置 $Model不是模板,是你自己先前链接数据库返回的对象...我的是改为$Form

  5. C#开发实例 键盘篇

    键盘的操作控制: 键盘和鼠标一样是重要输入设备的一部分.开发过程中,会涉及到很多的键盘操作控制. 2.1获取键盘信息 ①获取组合键 Windows中有很多默认的组合键,如Ctrl+v,Ctrl+A.本 ...

  6. Linux时间同步配置方法

    由于是在做mongoDB的实验中再一次的遇到了mongos路由节点同步时由于ntp时间的问题导致同步非常的慢.故写了个时间同步的语句===> while :; do rdate -s 192.1 ...

  7. 34.数组中2个只出现一次的数字[Find two numbers which appear once]

    [题目] 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字.要求时间复杂度是O(n),空间复杂度是O(1). [分析] 这是一道很新颖的关于位运算的面试题. ...

  8. cocos2dx混合模式应用———制作新手引导高亮区域

    先看下效果 制造这个椭圆高亮区域所使用原图是 附上代码 bool HelloWorld::init() { ////////////////////////////// // 1. super ini ...

  9. MongoDB副本集学习(二):基本测试与应用

    简单副本集测试 这一节主要对上一节搭建的副本集做一些简单的测试. 我们首先进入primary节点(37017),并向test.test集合里插入10W条数据: . rs0:PRIMARY> ;i ...

  10. 利用 Chromium Embedded Framework (CEF) 定制提取 Flash 视频的浏览器

    功能介绍: 利用 CEF 分析网页源码, 提取 flash 视频的代码. 提取的视频代码 LoadString 和 JS 两种方式重新插入到浏览器. (CEF_3.2171.1979_win32 - ...