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. 

InputThe 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) 
OutputFor 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.
题意:动物园有猫和狗,一个孩子有喜欢和不喜欢的动物,喜欢猫就一定讨厌狗,反之亦然,现可拿走动物使孩子最高兴
题解:最大独立集,二分图的最大独立集=顶点数-二分图最大匹配,接下来就是建图,把孩子当作点,如果某个孩子喜欢的动物是另一个讨厌的,那么就连边
我们希望减少最小的孩子数来满足所有人的喜好,这就是最小点覆盖。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; int n,m,p,color[N];
bool used[N],ok[N][N];
struct edge{
string a,b;
}e[N]; bool match(int x)
{
for(int i=;i<=p;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(color[i]==-||match(color[i]))
{
color[i]=x;
return ;
}
}
}
return ;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
while(cin>>n>>m>>p){
memset(ok,,sizeof ok);
for(int i=;i<=p;i++)
{
cin>>e[i].a>>e[i].b;
e[i].id=i;
}
for(int i=;i<=p;i++)
for(int j=;j<=p;j++)
if(e[i].a==e[j].b||e[i].b==e[j].a)
ok[i][j]=ok[j][i]=;
/* for(int i=1;i<=p;i++)
{
for(int j=1;j<=p;j++)
cout<<ok[i][j];
cout<<endl;
}*/
int ans=;
memset(color,-,sizeof color);
for(int i=;i<=p;i++)
{
memset(used,,sizeof used);
ans+=match(i);
}
cout<<p-ans/<<endl;
}
return ;
}

hdu3829最大独立集的更多相关文章

  1. hdu3829(最大独立集)

    传送门:Cat VS Dog 题意:动物园有N只猫,M只狗,P个小孩.每个小孩都有自己喜欢的动物和讨厌的动物,如果他喜欢狗,那么就讨厌猫, 如果他讨厌狗,那么他就喜欢猫.某个小孩能开心,当且仅当他喜欢 ...

  2. HDU3829(KB10-J 二分图最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  3. HDU3829:Cat VS Dog(最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  4. HDU3829 Cat VS Dog —— 最大独立集

    题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. hdu3829 二分匹配 最大独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...

  6. HDU3829 Cat VS Dog

    题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...

  7. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  8. 【BZOJ-4316】小C的独立集 仙人掌DP + 最大独立集

    4316: 小C的独立集 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 57  Solved: 41[Submit][Status][Discuss] ...

  9. loj 1201(最大独立集)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26913 思路:水题一枚,就是求最大独立集.最大独立集=顶点数-最大 ...

随机推荐

  1. Linux块设备驱动(一) _驱动模型

    块设备是Linux三大设备之一,其驱动模型主要针对磁盘,Flash等存储类设备,本文以3.14为蓝本,探讨内核中的块设备驱动模型 框架 下图是Linux中的块设备模型示意图,应用层程序有两种方式访问一 ...

  2. Ubuntu部署Jupyter

    前言 Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言.在本文中,我们将介绍 Jupyter notebook 的主要特 ...

  3. 在Windows的DOS中运行java编程中的问题

    1.苦恼着我的就是找不到或无法加载主类!

  4. Linux之tr命令

    tr - translate or delete characters 删除或替换文字信息 参数: -d  删除字符串 -s  删除重复的字符串只保留一个 [root@BASE ~]# cat c.t ...

  5. Windows 10 Creaters Update 画中画模式和窗口高斯模糊

    在Windows 10 Creaters Update中,可以给窗口设置高斯模糊了,只要几行代码! <Grid Loaded="Grid_Loaded"> <Gr ...

  6. 【SoDiaoEditor更新啦】--谨以献给那些还在医疗行业奋斗的小伙伴们

    先放github地址:https://github.com/tlzzu/SoDiaoEditor.v2 首先,这不是愚人节的玩笑,,, 本想着三月底发布来着,结果昨天又在兼容性上调出几个bug,然后拖 ...

  7. WebStorm里使用注意点

    归纳一些我在使用webstorm里遇到的问题: 1.问题:文件出现红线,如图 解决方案:可能是由于语言版本的问题,改一下版本试试 2.快捷键:http://www.cnblogs.com/yeming ...

  8. 回答: 2017-03-19的关于css+div布局的疑问 2017-04-05

    原问题为红色,回答为黑色 第一次布局一个静态网页,发现许多细节都需要自己探索,出现诸如以下问题: 1.布局问题:经常出现一个div被挤出来?做到一半少一个div布局? 布局之前,要点打好框架,明确每个 ...

  9. c++ 字符串去重

    ##### c++ 字符串去重 == 需求 == * 编写一个字符串过滤函数,若字符串出现多个相同的字符,将不是首次出现的字符过滤掉. > 输入:"apache" 输出:&q ...

  10. dotnet Core 调用HTTP接口,系统大量CLOSE_WAIT连接问题的分析,尚未解决。

    环境: dotnet core 1.0.1 CentOS 7.2 今天在服务器巡检的时候,发现一个服务大量抛出异常 异常信息为: LockStatusPushError&&Messag ...