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. ldd查询命令或软件共享的函数库(动态)

    <1> ldd - print shared library dependencies SYNOPSIS ldd [OPTION]... FILE... DESCRIPTION ldd p ...

  2. MVC ActionResult JsonResult

    以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...

  3. 取出type="button" 和type="text" 里面的值显示在页面

    <script  type="text/JavaScript> function changeLink() { document.getElementById("nod ...

  4. Linux下永久修改主机名

    红帽系列的Linux发行版主机名存放位置是/etc/sysconfig/network,Ubuntu Linux主机名存放位置是/etc/hostname,所以只要修改主机名存放文件便可以永久的修改计 ...

  5. Transfer-Encoding: chunked

    Http1.1中 使用 chunked 编码传送时 没有CONTENT_LENGTH,下载之前无法确定要下载的大小. Wininet中已经内嵌该传输协议,要查看chunked块的大小只能socket底 ...

  6. IOS多线程(NSThread)

    1.创建方法 使用NSThread创建线程主要有两个个方法,分别如下 NSThread* myThread = [[NSThread alloc] initWithTarget:self   sele ...

  7. Js数组里删除指定的元素(不是指定的位置)

    转载自:http://my.oschina.net/zh119893/blog/265964 之前一直是做后端的,从来也没有写过js,但是却一直想学学,也只是基于兴趣而已!现在到了这个公司,确实大量的 ...

  8. vmware安装linux.iso

    安装方法 : .进入Fedora后,在虚拟机选项栏中选VM->install vmware tools 拷贝VMware Tools.tar.gz到指定文件夹,解压缩 进入超级终端:在-> ...

  9. hp unix

    HP-UNIX 命令大全 #vgdisplay -v vgname #lvdisplay -v lvfullpath #pvdisplay -v pvfullpath # ioscan –fnkC d ...

  10. sqlserver临时启用和关闭约束

    select  'ALTER TABLE ['  + b.name +  '] NOCHECK CONSTRAINT ' +  a.name +';' as  禁用约束   from  sysobje ...