hdu 3829 Cat VS Dog 二分图匹配 最大点独立集
Cat VS Dog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
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.
题意:给你m只狗跟n只猫,p个人,每个人有一只喜欢和不喜欢的动物;
可以选取一些动物,使得满足条件的人最多;
满足条件:一个人的喜欢的动物在,并且不喜欢的动物不在;
思路:二分图匹配最大点独立集模型=所有人-最大匹配;
把所有人的对立的关系连边;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-6
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e3+,M=1e6+,inf=1e9+;
const LL INF=5e17+,mod=1e9+; int n,m;
int mp[N][N];
int linker[N];
bool used[N];
bool dfs(int a)
{
for(int i=;i<n;i++)
if(mp[a][i]&&!used[i])
{
used[i]=true;
if(linker[i]==-||dfs(linker[i]))
{
linker[i]=a;
return true;
}
}
return false;
}
int hungary()
{
int result=;
memset(linker,-,sizeof(linker));
for(int i=;i<n;i++)
{
memset(used,,sizeof(used));
if(dfs(i)) result++;
}
return result;
}
string l[N],disl[N];
int main()
{
int c,d;
while(~scanf("%d%d%d",&c,&d,&n))
{
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
cin>>l[i]>>disl[i];
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(l[i]==disl[j]||disl[i]==l[j])
mp[i][j]=;
}
}
int cnt=hungary();
printf("%d\n",n-cnt/);
}
return ;
}
hdu 3829 Cat VS Dog 二分图匹配 最大点独立集的更多相关文章
- hdu 3829 Cat VS Dog 二分匹配 最大独立点集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829 题目大意: 给定N个猫,M个狗,P个小朋友,每个小朋友都有喜欢或者不喜欢的某猫或者某狗 管理员从 ...
- HDU - 3829 Cat VS Dog (二分图最大独立集)
题意:P个小朋友,每个人有喜欢的动物和讨厌的动物.留下喜欢的动物并且拿掉讨厌的动物,这个小朋友就会开心.问最多有几个小朋友能开心. 分析:对于每个动物来说,可能既有人喜欢又有人讨厌,那么这样的动物实际 ...
- 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 3829——Cat VS Dog——————【最大独立集】
Cat VS Dog Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- 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 (最大独立集)【二分图匹配】
<题目链接> 题目大意: 动物园有n条狗.m头猫.p个小孩,每一个小孩有一个喜欢的动物和讨厌的动物.如今动物园要转移一些动物.假设一个小孩喜欢的动物在,不喜欢的动物不在,他就会happy. ...
- HDU 3829 - Cat VS Dog (二分图最大独立集)
题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...
- HDU 3829 Cat VS Dog(最大独立集)
题目大意: 有n只猫,有m只狗.现在有P个学生去参观动物园.每个孩子有喜欢的动物和不喜欢的动物.假如他喜欢猫那么他就一定不喜欢狗(反之亦然). 如果一个孩子喜欢一个动物,那么这个动物不会被移除,若是不 ...
- HDU 3829 Cat VS Dog
题意: p个人 每一个人有喜欢和讨厌的动物 假设选出的动物中包括这个人喜欢的动物同一时候不包括他讨厌的动物那么这个人会开心 问 最多几个人开心 思路: 二分图最大独立集 利用人与人之间的冲突 ...
随机推荐
- 自学Java第七周的总结
这一周里我将看过的知识点又复习了一遍,下个星期打算将题做一遍
- github开源的一些ip解析 ,运营商信息,经纬度 地址 后续开发使用
https://github.com/wzhe06/ipdatabase ip解析 https://github.com/flyaction/ipdatabase 比较新 https://githu ...
- onclick或者其他事件在部分移动端无效的问题
最近开发碰到一个问题,大多数手机都可以正常访问点击,但是有部分手机onclick无效,不知道可能是什么原因?该如何解决? 我遇到的这个问题,实际不是onclick的原因,而是因为js里面包含es6的语 ...
- Prometheus监控学习笔记之Prometheus的架构及持久化
0x00 Prometheus是什么 Prometheus是一个开源的系统监控和报警工具,特点是 多维数据模型(时序列数据由metric名和一组key/value组成) 在多维度上灵活的查询语言(Pr ...
- Docker学习笔记之运行和管理容器
0x00 概述 容器是基于容器技术所建立和运行的轻量级应用运行环境,它是 Docker 封装和管理应用程序或微服务的“集装箱”.在 Docker 中,容器算是最核心的部分了,掌握容器的操作也是 Doc ...
- Python 使用 face_recognition 人脸识别
Python 使用 face_recognition 人脸识别 官方说明:https://face-recognition.readthedocs.io/en/latest/readme.html 人 ...
- 【面试篇】必须掌握的Spring 常用注解
注解本身没有功能的,就和 xml 一样.注解和 xml 都是一种元数据,元数据即解释数据的数据,这就是所谓配置. 本文主要罗列 Spring|Spring MVC相关注解的简介. Spring部分 1 ...
- 01: Django rest framework 基础
1.1 RESTful API设计规范 参考地址: http://www.cnblogs.com/wupeiqi/articles/7805382.html 1.API与用户的通信协议,总是使用H ...
- Sublime Text安装与配置
1.1 下载安装Sublime Text 3 参考博客:https://www.cnblogs.com/Rising/p/3741116.html 1.下载安装Sublime Text 3 1. 下 ...
- mint-ui之Swipe使用
<template> <div> <div class="swipe-wrapper"> <mt-swipe :auto="10 ...