HDU3829:Cat VS Dog(最大独立集)
Cat VS Dog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 4751 Accepted Submission(s): 1757
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:
Sample Output:
1
3
Hint:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define mem(x) memset(x,0,sizeof(x))
using namespace std; const int N = ;
int n,m,p,ans;
char like[N][],dlike[N][]; //这里我一开始数组开的是4,WA了,开成5就AC了
int check[N],match[N],link[N][N]; inline int dfs(int x){
for(int i=;i<=p;i++){
if(link[x][i] && !check[i]){
check[i]=;
if(!match[i] || dfs(match[i])){
match[i]=x;
return ;
}
}
}
return ;
} int main(){
while(~scanf("%d%d%d",&n,&m,&p)){
mem(match);mem(link);ans=;
for(int i=;i<=p;i++){
scanf("%s%s",like[i],dlike[i]);
}
for(int i=;i<=p;i++)
for(int j=;j<=p;j++)
if(strcmp(like[i],dlike[j])== || strcmp(like[j],dlike[i])==) link[i][j]=;
for(int i=;i<=p;i++){
mem(check);
if(dfs(i)) ans++;
}
printf("%d\n",p-ans/);
}
return ;
}
HDU3829:Cat VS Dog(最大独立集)的更多相关文章
- HDU3829 Cat VS Dog —— 最大独立集
题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Hdu3829 Cat VS Dog(最大独立点集)
Cat VS Dog Problem Description The zoo have N cats and M dogs, today there are P children visiting t ...
- HDU3829 Cat VS Dog
题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...
- HDU 3829 Cat VS Dog (最大独立集)【二分图匹配】
<题目链接> 题目大意: 动物园有n条狗.m头猫.p个小孩,每一个小孩有一个喜欢的动物和讨厌的动物.如今动物园要转移一些动物.假设一个小孩喜欢的动物在,不喜欢的动物不在,他就会happy. ...
- hdu 2768 Cat vs. Dog 最大独立集 巧妙的建图
题目分析: 一个人要不是爱狗讨厌猫的人,要不就是爱猫讨厌狗的人.一个人喜欢的动物如果离开,那么他也将离开.问最多留下多少人. 思路: 爱猫和爱狗的人是两个独立的集合.若两个人喜欢和讨厌的动物是一样的, ...
- (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 ...
- HDU 3829——Cat VS Dog——————【最大独立集】
Cat VS Dog Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- Cat VS Dog HDU_3829(最大独立集最大匹配)
Cat VS Dog 题意:一群小朋友去动物园,如果每个小朋友喜欢的动物是猫,那么不喜欢的动物一定是狗,反之也是.现在动物园的管理者要拿走一些动物,如果拿走的是某个小朋友不喜欢的动物,那这个小朋友就非 ...
- HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...
随机推荐
- Preparing Cities for Robot Cars【城市准备迎接自动驾驶汽车】
Preparing Cities for Robot Cars The possibility of self-driving robot cars has often seemed like a f ...
- debounce、throttle、requestAnimationFrame
今天review同事代码,代码实现了返回顶部的功能,用到了lodash库中的throttle,我看着眼生,于是乎去看了下lodash文档,然后牵出了debounce,具体的知识点,这里不再赘述,底部的 ...
- Ubuntu14.04安装opencv2.4.13
本文参考相关链接:http://blog.csdn.net/honyniu/article/details/46390097 系 统:Ubuntu 14.04 x64 opencv版本:2.4.1 ...
- PHP.44-TP框架商城应用实例-后台19-权限管理-RBAC需求分析
RBAC:Role Based Access Control:基于角色的访问控制 需求分析:[类似效果如下图] 1.权限,角色,管理员 2.权限管理[无限级] 注意:权限会被分配给角色,而不是给管理员 ...
- 类 java.util.Collections 提供了对Set、List、Map进行排序、填充、查找元素的辅助方法。
类 java.util.Collections 提供了对Set.List.Map进行排序.填充.查找元素的辅助方法. 1. void sort(List) //对List容器内的元素排序,排序的规 ...
- 【连载】Maven系列(四)——配置私服
相关文章 1.<用起来超爽的Maven——入门篇> 2.<用起来超爽的Maven——进阶篇> 3.<Maven系列(三) 进阶> 一.为什么需要私服 有些公司并不提 ...
- error LNK2001: unresolved external symbol "public: __thiscall ControllerInterface::ControllerInterface(class QObject *)" (??0ControllerInterface@@QAE@PAVQObject@@@Z) downloadcontroller.obj
前几天刚遇到这个问题,但是今天再碰到就又要思考怎么解决.这次特别记录一下,以防下次碰到再手足无措: 1.看到这个报错第一感觉LNK关键字,表示连接错误,这种错误有几个可以下手的点 1)函数声明和定义是 ...
- 「个人训练」Can you solve this equation?(HDU-2199)
题意与分析 纯粹水题.本来想做下放松心情的,结果还是被坑了qaq 重点就是在浮点误差.比较左右的下次就直接上1e-10,别看着题目说1e-4然后给个-5,结果暴wa.气傻了..... 代码 #incl ...
- 使用Vue-cli 3.x搭建Vue项目
一.Vue-cli 3.x安装 Node 版本要求:Vue CLI 需要 Node.js 8.9 或更高版本 (推荐 8.11.0+) npm install -g @vue/cli 查版本是否正确 ...
- Linux-Shell脚本编程-学习-6-Shell编程-使用结构化命令-文件比较-case编程
这一片主要说test文件的比较,文件比较在日常使用的频率比较高,这里重点把每个部分都试着说说看 1. 检车目录 -d -d测试会检查指定的文件名是否在系统上以目录的形式存在,当我们要写文件到某个目录之 ...