hdu3829
来源:互联网 发布:配置php开发环境 编辑:程序博客网 时间:2024/05/29 09:46
B - Cat VS Dog
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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.
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)
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 2C1 D1D1 C11 2 4C1 D1C1 D1C1 D2D2 C1
Sample Output
13
有C个猫咪,D只汪,P个孩子,每个孩子要么喜欢猫,要么喜欢狗,如果把小孩A不喜欢的动物拿走,那么他就会开心,尝试拿走一些动物,使最多的小孩子开心,输出最多几人开心
将喜欢的和不喜欢的放在两列,如果一动物既有人喜欢,又有人讨厌,那么这就是一组矛盾,如果求出最少的矛盾对数,岂不是找到了最大开心人数,最大独立集=定点数-最大匹配数,就是独立集内的人和那些矛盾集没有关系,哎怎么矛盾怎么矛盾
#include <iostream>#include <map>#include <string.h>#include <stdio.h>#include <string>#include <math.h>using namespace std;const int maxn=1010;const int inf=0x3f3f3f3f;int C,D,P;int g[maxn][maxn];int linker[maxn];bool used[maxn];int n;bool dfs(int u){ for(int i=1; i<=n; i++) { if(!used[i]&&g[u][i]) { used[i]=true; if(!linker[i]||dfs(linker[i])) { linker[i]=u; return true; } } } return false;}int solve(){ int ans=0; memset(linker,0,sizeof(linker)); for(int i=1; i<=n; i++) { memset(used,false,sizeof(used)); if(dfs(i)) ans++; } return ans;} char str1[510][10],str2[510][10];int main(){ while(~scanf("%d%d%d",&C,&D,&P)) { n=P; memset(g,0,sizeof(g)); for(int i=1;i<=P;i++) cin>>str1[i]>>str2[i]; for(int i=1;i<=P;i++) { for(int j=1;j<=P;j++) { if(strcmp(str1[i],str2[j])==0) g[j][i]=g[i][j]=1; } } printf("%d\n",P-solve()/2); } return 0;}
0 0
- hdu3829
- hdu3829
- HDU3829-Cat VS Dog
- HDU3829 (9/600)
- HDU3829 【最大独立子集】
- HDU3829 Cat VS Dog
- HDU3829-最大独立子集
- hdu3829及二分图最大匹配模板
- hdu3829 二分图的最大独立集
- 【HDU3829】【二分匹配】【最小独立集】【问啥建啥】
- hdu3829 二分匹配 最大独立集
- hdu3829(二分图,最大独立集)
- 二分图最大独立集题目汇总 HDU3829,POJ1446、2771
- hdu3829—二分图求最大独立集
- hdu3829 Cat VS Dog(二分最大独立集)
- hdu3829——Cat VS Dog(最大独立集)
- Hdu3829 Cat VS Dog(最大独立点集)
- hdu3829-Cat VS Dog(最大独立集,匹配问题)
- 证明正方形和圆有交点
- Image I/O
- 两个链表的第一个公共结点
- 单片机驱动继电器
- spring @RequestBody The request sent by the client was syntactically incorrect.
- hdu3829
- Java线程:概念与原理
- C++字符串学习(三)
- 函数指针的用途
- 聊聊R的优势
- Oralce中delete和delete from
- python 取代字符串中的某项 replace,split, join
- 输入两个整数序列。其中一个序列表示栈的push顺序, 判断另一个序列有没有可能是对应的pop顺序。 为了简单起见,我们假设push序列的任意两个整数都是不相等的
- UVALive2889 Palindrome Numbers(回文数,神级代码....)