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 ...
随机推荐
- Hibernate - SQLQuery
使用SQLQuery 对原生SQL查询执行的控制是通过SQLQuery接口进行的,通过执行Session.createSQLQuery()获取这个接口.下面来描述如何使用这个API进行查询. 标量查询 ...
- 你不需要jQuery(三):新AJAX方法fetch()
XMLHttpRequest来完成ajax有些老而过时了. fetch()能让我们完成类似 XMLHttpRequest (XHR) 提供的ajax功能.它们之间的主要区别是,Fetch API 使用 ...
- MVC 自定义AuthorizeAttribute 实现权限验证
MVC内置的AuthorizeFilter先于Action/Result过滤器执行,为网站权限验证提供了很好的一套验证机制. 通过自定义的AuthorizeAttribute可以实现对用户权限的验证. ...
- httpclient 302 重定向
主要是由于页面可能不是通过 request.sendRedirect跳转的,可能通过js location跳转的.所以需要拿跳转后的 地址,重新发送请求...如下所示 if (status == H ...
- POJ2031Building a Space Station
http://poj.org/problem?id=2031 题意:你是空间站的一员,太空里有很多球形且体积不一的“小房间”,房间可能相距不近,也可能是接触或者甚至是重叠关系,所有的房间都必须相连,这 ...
- android 动态改变listview的内容
本文模拟:点击一个按钮,为已有的listview添加一行数据 <?xml version="1.0" encoding="utf-8"?> < ...
- Jquery-DataTable 使用介绍
http://dt.thxopen.com/example/server_side/simple.html
- 从iPhone4、iPhone5、iPhone6看手机外壳加工工艺进化史
从iPhone4.iPhone5到iPhone6,苹果为我们推出了一代又一代新产品,让我们享受到最新的科技产品.每次不只是配置上的改变,苹果在工艺上也不断改变.下面就阐述一下我对这几款手机在设计和制造 ...
- Android:实现无标题的两种方法
实现无标题的两种方法:配置xml文件和编写代码设置 1.在AndroidManifest.xml文件中进行配置 实现全屏效果: android:theme="@android:style/T ...
- Java读写Windows共享文件夹 .
版权声明:本文为博主原创文章,未经博主允许不得转载. 项目常常需要有访问共享文件夹的需求,例如共享文件夹存储照片.文件等.那么如何使用Java读写Windows共享文件夹呢? Java可以使用JCIF ...