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 ...
随机推荐
- 使用Unity拦截一个返回Task的方法
目标 主要是想为服务方法注入公用的异常处理代码,从而使得业务代码简洁.本人使用Unity.Interception主键来达到这个目标.由于希望默认就执行拦截,所以使用了虚方法拦截器.要实现拦截,需要实 ...
- [转载]easyui datagrid 时间格化(JS 日期时间本地化显示)
easyui datagrid 日期时间显示不正常,后台java 类型为 DATE 经过JSON工具一转化传到前台来就是这样,不便 于是想格式化一下, 格式化代码 如下: [javascript] v ...
- 1964-NP
描述 Problems in Computer Science are often classified as belonging to a certain class of problems (e. ...
- 一周一话题之四(JavaScript、Dom、jQuery全面复习总结<Dom篇>)
-->目录导航 一. 初探Dom 1. Dom介绍 二. Dom基础 1. window顶级对象 2. body.document对象事件 3. 通用的HTML元素的事件 4. 冒泡事件 5. ...
- WebLoigc的配置(生产模式与开发模式)
1.Weblogic两种模式的切换1).生产模式--->开发模式将domain路径下的bin\setDomainEnv.cmd文件中set PRODUCTION_MODE=true改为set P ...
- perl杂项
perl -pi -e 's|googleapis.com|useso.com|g' `find ./ -type f` yingc@yingc:~/gcyin/test/thirdparty/ffm ...
- javaweb学习总结(四十七)——监听器(Listener)在开发中的应用
监听器在JavaWeb开发中用得比较多,下面说一下监听器(Listener)在开发中的常见应用 一.统计当前在线人数 在JavaWeb应用开发中,有时候我们需要统计当前在线的用户数,此时就可以使用监听 ...
- Hadoop伪分布模式配置部署
.实验环境说明 注意:本实验需要按照上一节单机模式部署后继续进行操作 1. 环境登录 无需密码自动登录,系统用户名 shiyanlou,密码 shiyanlou 2. 环境介绍 本实验环境采用带桌面的 ...
- chinacloud大数据新闻
2015年大数据发展八大趋势 (0 篇回复) “数据很丰满,信息很骨感”:Sight Machine想用大数据的方法,打碎两者间的屏障 (0 篇回复) 百度携大数据"圈地" ...
- 使用Spring框架的12个开源项目
使用Spring框架的12个开源项目 http://www.csdn.net/article/2013-10-14/2817176-open-source-projects-that-use-spri ...