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. OpenGL笔记(二) 渲染管线

    GLSL着色器代码分为两个部分,即Vertex Shader(顶点着色器)与Fragment Shader(片元着色器). 上下文环境搭建 OGL不负责窗口管理与上下文环境管理,该职责由平台完成.在A ...

  2. Loopback接口用途---用作管理地址。

    Loopback接口的优点是永远不会down点,不管是链路断开还是网卡损坏.因而loopback接口有很高健壮性. 但是loopback并非实际网口,外部设备要与该口通信,必须经过实际口的路由实现. ...

  3. sql语句之随机查询记录和批量插入--基于mysql

    本周遇到了好几次数据库方面的问题,一个是上一篇文章提到的因为要修改数据结构引起的在表间复制字段的需求,另一个就是这篇文章要写的:1,从某个数据表中按照某个字段不重复的随机选取几百条记录:2,然后把这些 ...

  4. 20155204《网络对抗》Exp8 Web基础

    20155204<网络对抗>Exp8 Web基础 一.基础问题回答 1.什么是表单 表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用C ...

  5. 复选框、单选框 jquery判断是否选中Demo

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="eachcheckbox.a ...

  6. 《图说VR入门》——DeepoonVR的大鹏(陀螺仪)枪

    <图说VR入门>--VR大朋的(陀螺仪)枪 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/ar ...

  7. vim打开多窗口、多文件之间的切换

    打开多个文件: 一.vim还没有启动的时候: 1.在终端里输入  vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :e file 可以再打开一 ...

  8. 汇编 EBP ,ESP 寄存器

    知识点:  CALL框架  EBP寄存器 栈底指针  ESP寄存器 栈顶指针 一.EBP栈底指针 EBP是一个特殊的寄存器,通过EBP+偏移量 可以访问CALL里边的局部变量.它的低16位叫BP ...

  9. Linux 设置core dump

    Linux 设置core dump

  10. Kubernetes学习之路(二十五)之Helm程序包管理器

    目录 1.Helm的概念和架构 2.部署Helm (1)下载helm (2)部署Tiller 3.helm的使用 4.chart 目录结构 5.chart模板 6.定制安装MySQL chart (1 ...