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. Unity 3D 关于给APK包加广告的流程

    http://hunterwang.diandian.com/post/2012-11-23/40042217286 最近一直纠结着用Unity给安卓的应用添加广告,用Unity3d做安卓我还是第一次 ...

  2. JAVA经典算法40题及解答

    JAVA经典算法40题 [程序1]   题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分 ...

  3. search in 2d matrix and serach minimum in rotated array

    import java.io.*; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collecti ...

  4. ubuntu 快速安装jre

    sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-i ...

  5. Linux rpm安装问题解决

    1.安装时提示:warning: *.rpm: Header V3 RSA/SHA256 Signature, keykey ID c105b9de: NOKEY 解决的方法就是在rpm 语句后面加上 ...

  6. NYOJ 61传纸条(一) 双线程DP问题

    http://www.cnblogs.com/HpuAcmer/archive/2012/05/06/2486591.html 题目链接:http://acm.nyist.net/JudgeOnlin ...

  7. 阿里云vps上mysql挂掉的解决办法

    阿里云vps上mysql挂掉的解决办法 4条回复 用阿里云的vps用作blog服务器,系统很稳定,已经100多天一直运行正常,大概从上个月开始发现blog的mysql会有时挂掉,会收到短信通知.之前没 ...

  8. docker的四种网络模式

    /* 1. host模式 : docker run 使用 --net=host指定 docker使用的网络实际上和宿主机一样 2. container模式: 使用 --net=container:co ...

  9. Linux运维

    概要:http://os.51cto.com/art/201312/423616.htm 论坛: http://www.linux360.cn/ https://www.centos.bz/ http ...

  10. Solr5.3.1通过copyField设置多个field(字段)同时检索

    如果业务需要我们对多个field同时进行检索,有没有什么好的办法呢?非常幸运的是Solr为我们提供了copyField对多个field进行索引和检索.然而配置也非常简单. 修改schame.xml,添 ...