题意:每个人有喜欢的猫和不喜欢的狗。留下他喜欢的猫他就高心,否则不高心。问最后最多有几个人高心。

思路:二分图求最大匹配

 #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 (二分匹配 求 最大独立集)的更多相关文章

  1. hdu 2768 Cat vs. Dog (二分匹配)

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu 3829 Cat VS Dog 二分匹配 最大独立点集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从 ...

  3. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

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

  4. 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 ...

  5. HDU——2768 Cat vs. Dog

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  7. HDU - 1045 Fire Net(二分匹配)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

  8. hdu 1528 Card Game Cheater (二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 3829——Cat VS Dog——————【最大独立集】

    Cat VS Dog Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

随机推荐

  1. [转载]c# 多线程一个带多个参数的方法

    比如我要线程一个private void subPing(int pre,int end) 我在Thread t=之后应该如何写 用匿名委托吧!那么简单为什么要这样写!t = new Thread(d ...

  2. hdu 4652 Dice 概率DP

    思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...

  3. FileZilla Server 防火墙端口开启设置 windows 2008 win

    入站规则 添加21端口, 程序FileZilla server.exe 出站规则 %SystemRoot%\System32\ftp.exe

  4. SPRING IN ACTION 第4版笔记-第九章Securing web applications-005-Applying LDAP-backed authentication

    一. 1.This method is the  LDAP analog to  jdbcAuthentication() @Override protected void configure(Aut ...

  5. 拒绝卡顿——在WPF中使用多线程更新UI

    原文:拒绝卡顿--在WPF中使用多线程更新UI 有经验的程序员们都知道:不能在UI线程上进行耗时操作,那样会造成界面卡顿,如下就是一个简单的示例: public partial class MainW ...

  6. 发现可高速缓存的 SSL 页面

    发现可高速缓存的 SSL 页面 技术描述: 缺省情况下,大部分 Web 浏览器都配置成会在使用期间高速缓存用户的页面. 这表示也会高速缓存 SSL 页面.不建议让 Web 浏览器保存任何 SSL 信息 ...

  7. IE Web 开发支持将迁移到 StackOverflow

    http://stackoverflow.com/questions/tagged/internet-explorer

  8. QMenu的个性化定制

    经常使用菜单,菜单的定制相当重要,普通的样式设置不难,一般需求足以实现(QMenu + QAction).如果要足够个性,则需要进行一定的定制.     说起定制,其实也是利用Qt中现成的组件进行组装 ...

  9. Foreman--管理PuppetClient

    一. 环境: 1. server: puppetmaster+activemq+foreman1.3 server1.xxx.com(10.8.1.201) 2. client: fedora 19 ...

  10. android系统平台显示驱动开发简要:LCD常用接口篇『二』

    平台信息:内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博客 ...