Cat VS Dog

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

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
 
Recommend
xubiao   |   We have carefully selected several similar problems for you:  3828 3830 3831 3832 3835 

不能以猫狗为顶点    那样找到的是哪些动物会转移   以小孩为顶点  找出最大点独立集   以小孩总数p为左右点集的顶点个数,假设小孩a喜欢的动物是小孩b不喜欢的动物   就连一条边edge(a,b)

记录猫和狗的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
int line[][], used[maxn], girl[maxn]; int nx, ny, n, m, p, cnt;
bool find(int x)
{
for(int j=; j<=p; j++)
{
if(line[x][j] == && used[j] == -)
{
used[j] = ;
if(girl[j] == || find(girl[j]))
{
girl[j] = x;
return ;
}
}
}
return ;
}
int main()
{
while(cin>> n >> m >> p)
{
int ret = ;
mem(line, );
char str1[][], str2[][];
for(int i=; i<=p; i++)
{
cin>> str1[i] >> str2[i];
for(int j=; j<i; j++)
if(strcmp(str1[i],str2[j]) == || strcmp(str1[j], str2[i]) == )
line[i][j] = line[j][i] = ;
}
mem(girl, );
for(int i=; i<=p; i++)
{
mem(used, -);
if(find(i))
ret++;
}
cout<< p-ret/ <<endl; } return ;
}

Cat VS Dog HDU - 3829 (最大独立集 )的更多相关文章

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

    题意:有P个孩子,有的孩子喜欢猫不喜欢狗,有的喜欢狗不喜欢猫(喜欢的和不喜欢的一定是相相对立的动物),动物园有N只猫,M只狗,每个孩子都有喜欢的猫讨厌的狗(或者喜欢的狗讨厌的猫),现在动物园要送走一批 ...

  2. Cat VS Dog HDU_3829(最大独立集最大匹配)

    Cat VS Dog 题意:一群小朋友去动物园,如果每个小朋友喜欢的动物是猫,那么不喜欢的动物一定是狗,反之也是.现在动物园的管理者要拿走一些动物,如果拿走的是某个小朋友不喜欢的动物,那这个小朋友就非 ...

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

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

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

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

  5. 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 ...

  6. (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 ...

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

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

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

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

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

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

随机推荐

  1. C#/JS AES字符串加密和解密

    往往我们有一种需求:在页面端实现对即将传入到后台端的某些字符串进行加密,然后在后台端对传入进来的字符串做解密.在一些有安全要求的数据传输上会用到此种方式 下面分别列出js端和后台端的加密或解密代码. ...

  2. WC 2019 游记 - 败者之低语

    败者之低语 WC 2019 游记 Day -1 看了一圈PKU和THU的题,感觉图像识别真有意思... 感觉非常讲道理,pku还是比thu简单一点的... 听说高二414在thu没有进面试? 震惊!( ...

  3. 利用Python统计微信联系人男女比例以及简单的地区分布

    寒暄的话不多说,直接进入主题. 运行效果图: [准备环境] Python版本:v3.5及其以上 开发工具:随意,此处使用Pycharm [依赖包] 1.itchat (CMD运行:pip instal ...

  4. Eclipse编辑器设置

    1. 自己不太喜欢Eclipse按回车后自动插入参数的默认选项. 可以在Window-Preferences-Java-Editor-Content Assist选项里,将Fill method ar ...

  5. C#中二进制、十进制和十六进制互相转换的方法

    二进制在C#中无法直接表示,我们一般用0和1的字符串来表示一个数的二进制形式.比如4的二进制为"100".下面介绍C#里面用于进制转换的方法. 十进制转换为二进制(int--> ...

  6. 设计模式 笔记 享元模式 Flyweight

    //---------------------------15/04/20---------------------------- //Flyweight 享元模式------对象结构型模式 /* 1 ...

  7. Centos 7 部署Kubernetes(K8S)集群

    资源链接:https://pan.baidu.com/s/1-PT_QQAf7cTu_znX-S-r9Q 密码:33sr 转发:http://blog.51cto.com/lizhenliang/19 ...

  8. Python机器学习/LinearRegression(线性回归模型)(附源码)

    LinearRegression(线性回归) 2019-02-20  20:25:47 1.线性回归简介 线性回归定义: 百科中解释 我个人的理解就是:线性回归算法就是一个使用线性函数作为模型框架($ ...

  9. PHP学习 例外和错误处理

    <?phptry{ open_folder("C:\\book");}catch(Exception $ex) { echo 'Error Message:'.$ex-> ...

  10. PHP学习 类型 变量 常数 运算符

    PHP支持下列8种类型 标量类型 scalar type整数 integer浮点数 float double布尔 boolean字符串 string 特殊类型 special typeNULL资源 r ...