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 ...
随机推荐
- c++调用matlab生成的Dll动态连接库
点击打开链接http://download.csdn.net/detail/nuptboyzhb/4228429 c++调用matlab生成的Dll动态连接库 实验平台: matlab 7.0(R ...
- Socat
http://www.oschina.net/p/socat/ tcpick https://sourceforge.net/projects/tcpick/
- winform学习日志(十九)----------真正三层架构之登录
摘要:一:三层构架的基础知识在项目开发的过程中,有时把整个项目分为三层架构,其中包括:表示层(UI).业务逻辑层(BLL)和数据访问层(DAL).三层的作用分别如下: 表示层:为用户提供交互操作界面, ...
- Android ListView避免多线程加载一个同一资源
当我们的ListView中的Item包含图片,而且这些图片是同一资源,我们用多线程去加载图片,这时候可能就发生了这种情况. 比如线程是人,第一个人去做加载图片到缓存的工作,还没做好时第二个人要这同一张 ...
- ConfigurationManager配置操作
/// <summary> /// 配置信息维护 /// </summary> public class AppConfig { public static Configura ...
- Vim 配色设置与配色脚本语法
几个给tag加颜色的插件 https://github.com/octol/vim-cpp-enhanced-highlight:基于tag的c family语法高亮 https://github.c ...
- URAL1501. Sense of Beauty(记忆化)
链接 dfs+记忆化 对于当前状态虽然满足和差 但如果搜下去没有满足的情况也是不可以的 所以需要记忆化下 #include <iostream> #include<cstdio> ...
- MediaPlayer中创建AudioTrack的过程
使用MediaPlayer播放音视频时,会创建AudioTrack对象用于播放音频数据.下面就来看看MediaPlayer创建AudioTrack的过程: 1.创建AudioTrack对象MediaP ...
- git恢复被修改的文件
恢复到最后一次提交的改动: git checkout -- + 需要恢复的文件名 但是,需要注意的是,如果该文件已经 add 到暂存队列中,上面的命令就不灵光喽 需要先让这个文件取消暂存: git r ...
- jsoi2014前两轮回眸
今天从常州回来了,第二轮考得惨不忍睹 大概来总结一下前两轮: 第一轮是4个小时,3道题,一道网络流,一道环形DP,一道线段树 最后一道题ahoi的原题(传送bzoj1798),非常水的线段树,是个很好 ...