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 ...
随机推荐
- ruby $LOAD_PATH及类加载
$LOAD_PATH $LOAD_PATH 指的是Ruby读取外部文件的一个环境变量,其实和windows的环境变量是一个概念.Ruby会在这个环境变量的路径中读取需要require的文件,如果在环境 ...
- MOVE-PERCENTAGE(文字列の部分の代入)
以下の MOVE 命令のバリアントは.c 型項目についてのみ機能します. MOVE c1 TO c2 PERCENTAGE p [RIGHT]. 左寄せした (RIGHT オプションを指定した場合は右 ...
- 生産管理(PP)
伝票系 製造指図 マスタ系 生産資源/治工具 作業区 能力 作業手順 作業バージョン 作業記録 需要予測プロファイル 計画手配 MRP レシピ その他 カスタマイズ系 BOM関連 製造指図確認 伝票系 ...
- SAN---第二网的概念
网络技术的优缺点:优点:连接能力,超强路由,管理能力,远距离缺点:低速以及高负载,强烈的软件需求,错误检测能力 SAN:storage area network(存储区域网络)--是一种基于光网的特殊 ...
- A problem occurred evaluating project ':'. > ASCII
项目编译出错: 错误信息如下: FAILURE: Build failed with an exception. * Where: Build file 'F:\git\i***\build.grad ...
- nginx启动和配置
1.命令行参数 -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的.路径应为绝对路径 -t 不运行,而仅仅测试配置文件.nginx 将检查配置文件的语 ...
- 以太坊solidity编程常见错误(不定期更新)
1.报错: Expected token Semicolon got 'eth_compileSolidity' funtion setFunder(uint _u,uint _amount){ 解决 ...
- [转]使用 Travis CI 部署你的 Hexo 博客
之前使用Hexo的时候,都是在本地进行编译和部署的,平时使用的时候觉得没什么,只需要 hexo ghexo d 两步就可以把博客更新的内容推到GitHub Pages上.但是某些时候可能会遇到你的文件 ...
- android扁平化ProgressBar--progressWheel
ProgressWheel是git是一个开源项目,为开发者提供一个扁平化的ProgressBar,并可对其进行深度定制 1,将ProgressWheel的源码拷贝到项目中 public class ...
- penLDAP学习笔记
LDAP协议 目录是一组具有类似属性.以一定逻辑和层次组合的信息.常见的例子是通讯簿,由以字母顺序排列的名字.地址和电话号码组成.目录服务是一种在分布式环境中发现目标的方法.目录具有两个主要组成部分: ...