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. P2384 最短路

    题目背景 狗哥做烂了最短路,突然机智的考了Bosh一道,没想到把Bosh考住了...你能帮Bosh解决吗? 他会给你100000000000000000000000000000000000%10金币w ...

  2. day80

    昨日回顾 上节回顾: 中间件: -django请求生命周期: -中间件:对全局请求的修改,和全局响应的修改 -process_request:从上往下执行 -process_response:从下往上 ...

  3. navicat 连接Oracle 报错:Cannot load OCI DLL, 126

    1.64位win7 安装了oracle11g 使用Navicat for Oracle cannot load OCI DLL,126 解决方法:navicat 菜单中 -工具->选项-> ...

  4. strstr(),strchr()

    strstr($a, $b)和strchr()一样,起的别名,表示查找$a中第一次出现$b,并返回字符串的剩余部分: .strrchr()从后往前查第一个出现的 直接写两行代码: <?php $ ...

  5. sphinx搜索 笔记

    架构图: 安装sphinx,见文章http://my.oschina.net/ptk/blog/495435 sphinx关键的配置文件.在里面写查询的sql. 两个关键命令:indexer生成查询索 ...

  6. odoo之可选择多个内容显示问题

    <field name="partner_id" widget="many2many_tags" options="{'no_create': ...

  7. 详细解读大数据分析引擎Pig&PigLatin语句

    Pig 一.Pig的介绍: Pig由Yahoo开发,主要应用于数据分析,Twitter公司大量使用Pig处理海量数据,Pig之所以是数据分析引擎,是因为Pig相当于一个翻译器,将PigLatin语句翻 ...

  8. 剖析管理所有大数据组件的可视化利器:Hue

    日常的大数据使用都是在服务器命令行中进行的,可视化功能仅仅依靠各个组件自带的web界面来实现,不同组件对应不同的端口号,如:HDFS(50070),Yarn(8088),Hbase(16010)等等, ...

  9. python_环境的配置

    1.首先登入官网:https://www.python.org/downloads/windows/ 下载: 下载executable installer 2.安装 ipython,jupyter 地 ...

  10. EZ 2018 02 26 NOIP2018 模拟赛(一)

    这次是校内OJ(HHHOJ)线上比赛,网址:http://211.140.156.254:2333/contest/51 (我去刚刚快写完了手贱关掉了) 这次总体难度也不高,T1&&T ...