HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
题意:每个人有喜欢的猫和不喜欢的狗。留下他喜欢的猫他就高心,否则不高心。问最后最多有几个人高心。
思路:二分图求最大匹配
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
#define clc(a,b) memset(a,b,sizeof(a))
using namespace std;
const double eps=1e-;
const double pi=acos(-);
const int maxn=;
int linker[maxn];
bool used[maxn];
int n,m,p;
char cat[maxn][];
char dog[maxn][];
vector<int>vec[maxn];
int uN; bool dfs(int u)
{
for(int i=;i<vec[u].size();i++)
{
if(!used[vec[u][i]])
{
used[vec[u][i]]=true;
if(linker[vec[u][i]]==-||dfs(linker[vec[u][i]]))
{
linker[vec[u][i]]=u;
return true;
}
}
}
return false;
} int hungary(int n)
{
//int u;
int res=;
clc(linker,-);
for(int u=;u<n;u++)
{
clc(used,);
if(dfs(u))
res++;
}
return res;
} int main()
{
while(~scanf("%d%d%d",&n,&m,&p))
{
clc(vec,);
for(int i=;i<p;i++)
{
scanf("%s%s",cat[i],dog[i]);
}
for(int i=;i<p;i++)
{
for(int j=i+;j<p;j++)
{
if(!strcmp(cat[i],dog[j])||!strcmp(dog[i],cat[j]))
{
vec[i].push_back(j);
vec[j].push_back(i);
}
}
}
uN=hungary(p)/;
//cout<<uN<<endl;
printf("%d\n",p-uN);
}
return ;
}
HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)的更多相关文章
- hdu 2768 Cat vs. Dog (二分匹配)
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 3829 Cat VS Dog 二分匹配 最大独立点集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从 ...
- hdu 3829 Cat VS Dog 二分图匹配 最大点独立集
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Prob ...
- 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 ...
- HDU——2768 Cat vs. Dog
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- HDU - 1045 Fire Net(二分匹配)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
- hdu 1528 Card Game Cheater (二分匹配)
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 3829——Cat VS Dog——————【最大独立集】
Cat VS Dog Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
随机推荐
- [Ecmall]ECMALL目录结构设置与数据库表
最近在做ecmall的开发,ecmall在开源方面还有待进步啊,官方没有提供开发文档,也没有关于系统架构组织的贡献,使用者都要自己从0开始,官方论坛连二次开发板块都没有,都在哪瞎扯淡,广告一堆.可悲~ ...
- 找出程序cpu使用率高的原因
确定是CPU过高 使用top观察是否存在CPU使用率过高现象 找出线程 对CPU使用率过高的进程的所有线程进行排序 ps H -e -o pid,tid,pcpu,cmd --sort=pcpu |g ...
- linux下c/c++ IDE开发工具介绍
为避免以下某个软件安装时不自动安装 build-essential 不妨先执行: sudo apt-get install build-essential [编辑 ]anjuta Anjuta Dev ...
- C++开发必看 四种强制类型转换的总结
C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用. const_cast ...
- struts2 action中传递两个参数到url
<action name="outInDetail" class="formManage_outInDetailAction"> <resul ...
- IText 生成横向的doc文档
IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar 亲测无误,代码如下: import com.lowagie.t ...
- ZOJ 2563 Long Dominoes(状态压缩DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1563 题目大意:在h*w的矩阵里铺满1*3的小矩阵,共有多少种方法 ...
- linux xxd 命令
http://www.cnblogs.com/openix/archive/2012/04/23/2466320.html xxd -i dht.jpg dht.h
- SOA基础
每个系统上都有多种业务逻辑,这就像在一个小超市中,一个人负责收银.清洁.摆货.咨询等各种各样的事情,当来超市的顾客多到一定程度,这个人就没办法再负责这么多的事情了,系统也同样如此. 第一个现象就是系统 ...
- android系统平台显示驱动开发简要:LCD常用接口篇『二』
平台信息:内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博客 ...