Hdu3829 Cat VS Dog(最大独立点集)
Cat VS Dog
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
Next P lines, each line contains a child's like-animal and dislike-animal, C for cat and D for dog. (See sample for details)
C1 D1
D1 C1
1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
3
Case 2: Remove D1 and D2, that makes child 1, 2, 3 happy.
————————————————————————————————
题目的意思是有n个人,每个人有喜欢的动物和讨厌的动物,如果保留他喜欢的删去讨厌的他就很高兴,问最多让多少人高兴
思路:根据人喜恶互斥关系建图,然后二分图最大匹配求最大独立点集
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN,n; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int link[MAXN];
int vis[MAXN];
bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,k,x,y,T;
string s1[1005],s2[1005];
while(~scanf("%d%d%d",&x,&y,&m))
{ memset(g,0,sizeof g);
for(int i=0; i<m; i++)
{
cin>>s1[i]>>s2[i];
}
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
{
if(s1[i]==s2[j]||s2[i]==s1[j])
g[i][j]=1;
}
uN=vN=m;
printf("%d\n",m-hungary()/2);
}
return 0;
}
Hdu3829 Cat VS Dog(最大独立点集)的更多相关文章
- HDU3829 Cat VS Dog —— 最大独立集
题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU3829 Cat VS Dog
题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...
- HDU3829:Cat VS Dog(最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- 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 ...
- Cat VS Dog HDU - 3829 (最大独立集 )
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- Cat VS Dog
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
- HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...
- (hdu step 6.3.7)Cat vs. Dog(当施工方规则:建边当观众和其他观众最喜爱的东西冲突,求最大独立集)
称号: Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
随机推荐
- sharpsvn 继续,解决文件locked 问题,
方法中少个方法就会出现一些问题. 比如进行了断线测试,结果再操作时就出现了文件被锁的情况,最终查了官网的论坛,才得以解决 How to unlock if the working copy is lo ...
- Android.DebugTools.Traceview & dmtracedump
1. Android 调试工具之Traceview http://www.cnblogs.com/devinzhang/archive/2011/12/18/2291592.html TraceVie ...
- appache压力测试
apache自带压力工具测试说明: Usage: ab [options] [http[s]://]hostname[:port]/pathOptions are: -n requests Numbe ...
- SQL注入漏洞总结
目录: 一.SQL注入漏洞介绍 二.修复建议 三.通用姿势 四.具体实例 五.各种绕过 一.SQL注入漏洞介绍: SQL注入攻击包括通过输入数据从客户端插入或“注入”SQL查询到应用程序.一个成功的S ...
- 企业官网原型制作分享-Starbucks
星巴克是全球著名的咖啡连锁店,星巴克的产品不单是咖啡,咖啡只是一种载体.而正是通过咖啡这种载体,星巴克把一种独特的格调传送给顾客.咖啡的消费很大程度上是一种感性的文化层次上的消费,文化的沟通需要的就是 ...
- 第一个spring boot 程序
安装.运行.预览省略 错误1:8080端口被IIS占用,关闭它 Description: The Tomcat connector configured to listen on port 8080 ...
- IOS初级:UIScrollView & UIPageControl
UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...
- Bootstrap学习遇到的role属性--- 无障碍网页应用属性
以前接触过Bootstrap,但也只是仅仅接触,现在重新学习下,今天看到一个例子中的属性有一个role, 查阅资料发现这个是--WAI-ARIA无障碍设计属性: 通俗说是该设计为了一些盲人,失聪,残疾 ...
- Hibernate学习笔记:基础模型类
根据业务建模型时,有一些字段基本每个表都是需要的,如下表: package com.company.jelly.model; import javax.persistence.EntityListen ...
- Linux/Python学习路线
Linux: 初级阶段: 熟练掌握常用80个命令: 掌握Linux常用软件包的安装方法,如源码安装,rpm安装等: 学习安装设备驱动程序(如网卡,显卡驱动): 了解Grub/Lilo引导程序以及简单的 ...