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. 缩点tarjan

    给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和.允许多次经过一条边或者一个点,但是,重复经过的点,权值只计算一次. 缩点含义:将一个环缩成 ...

  2. 架构图+kubernetes 问题理解 -- kube-pproxy - endpoint

    1.详述kube-proxy原理,一个请求是如何经过层层转发落到某个pod上的整个过程.请求可能来自pod也可能来自外部. 1.1kube-proxy为集群提供service功能,相同功能的pods对 ...

  3. zabbix部署(1)(lnmp转)

    1.lnmp 首先 确保CentOS7上网络配置正确,可以正常访问互联网. 确保已经关闭了iptables. CentOS7上是firewall,关闭命令: 1 2 # systemctl stop  ...

  4. 参照示例搭建一个Quertz + Topshelf的一个作业调度服务(基础)

    学习网址:Quartz.NET 入门.使用Topshelf创建Windows服务 来自七七资料 1.直接下载源码 2.配置完成后,安装服务测试应用. 以下是遇到情况和加入的一些内容 1.在进行服务安装 ...

  5. 06-Git-Linux命令

    Git 命令 Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一.新建代码库 # 新建一个目录,将其初始化为Git代 ...

  6. (2)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- .NetCore启动配置 和 .NetCoreWebApi

    什么是.Net Core?.Net Core是微软开发的另外一个可以跨Linux.Windows.mac等平台的.Net.Net Core相关知识看文章地步dotnet dllname.dll 运行P ...

  7. Repository模式与UnitOfWorks模式的运用

    软件开发就像是一个江湖,而设计模式就是一本高深的秘籍每读一次.用一次.想一次都能得到新的领悟,让我们的设计技能有所提高.开始时我们可能会“为了模式而模式”,让代码变得乱78糟甚至难以让人理解,但随着设 ...

  8. Asp.Net_上传文件(ftp、webClient、webService)

    第一种:通过FTP来上传文件 首先,在另外一台服务器上设置好FTP服务,并创建好允许上传的用户和密码,然后,在ASP.NET里就可以直接将文件上传到这台 FTP 服务器上了.代码如下: <%@ ...

  9. python3 subprocess模块

    当我们在执行python程序的时候想要执行系统shell可以使用subprocess,这时可以新起一个进程来执行系统的shell命令,python3常用的有subprocess.run()和subpr ...

  10. 3.3V电源LDO

    1:今天用到1颗3.3v的LDO,如图 输入输出都是3.3V,但是一个是做模拟电压,以后遇到这种情况可以这样使用. 2:二极管降压电路,1.8V转1.5V