POJ 2771 Guardian of Decency(求最大点独立集)
该题反过来想:将所有可能发生恋爱关系的男女配对,那么可以带出去的人数应该等于这个二分图的最大独立集 先要做一下预处理,把不符合要求的双方先求出来, company[i][j]表示i、j四个标准都不符合,即他们可能会成为伴侣。
这里要注意因为x、y集合都是0~n-1,左右对称,所以求最大点独立集的点的个数时,最后还要/2。
接下来就是求最大独立集的点的个数。
最大点独立集+最小点覆盖=点的个数 独立集:在集合中的任意两点都不相邻,即两点间不存在边
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std; const int maxnx=;
const int maxny=; int company[maxnx][maxny]; //company[i][j]=1表示i、j四个条件全满足,有可能成为伴侣
int used[maxny];
int cnt,t,n,k;
int matchx[maxny]; struct Person{
int height;
int sex; //0代表女,1代表男
char music[],sports[];
}pupil[]; bool dfsfind(int k){
for(int i=;i<n;i++){
if(company[k][i] && !used[i]){
used[i]=;
if(matchx[i]==- || dfsfind(matchx[i])){
matchx[i]=k;
return true;
}
}
}
return false;
} int hungry(){
cnt=;
memset(matchx,-,sizeof(matchx));
for(int j=;j<n;j++){
memset(used,,sizeof(used));
if(dfsfind(j)){
cnt++;
}
}
return cnt; } void deal(){
Person p1,p2;
for(int i=;i<n;i++){
for(int j=i;j<n;j++){
p1=pupil[i];
p2=pupil[j];
if((abs(p1.height-p2.height)<=)&&(p1.sex!=p2.sex)&&(strcmp(p1.music,p2.music)==)&&(strcmp(p1.sports,p2.sports)!=)){
company[i][j]=;
company[j][i]=;
}
}
} }
int main()
{
char s1[];
scanf("%d",&t);
for(int q=;q<t;q++){
scanf("%d",&n);
memset(company,,sizeof(company)); for(int i=;i<n;i++){
scanf("%d%s%s%s",&pupil[i].height,s1,pupil[i].music,pupil[i].sports);
if(s1[]=='F')
pupil[i].sex=;
else
pupil[i].sex=;
}
deal(); int ans=(*n-hungry())/;
printf("%d\n",ans); }
return ;
}
POJ 2771 Guardian of Decency(求最大点独立集)的更多相关文章
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- POJ 2771 Guardian of Decency (二分图最大点独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6133 Accepted: 25 ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- UVA 12083 POJ 2771 Guardian of Decency
/* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- poj 2771 Guardian of Decency 解题报告
题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 Guardian of Decency
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
- poj 2771 Guardian of Decency(最大独立数)
题意:人与人之间满足4个条件之一即不能成为一对(也就说这4个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...
- POJ——T2271 Guardian of Decency
http://poj.org/problem?id=2771 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5932 A ...
随机推荐
- linux之Vim使用
Vim同Emac是Linux世界下最为流行的两个文本编辑工具,集中精力学习一个就好了,暂定以Vim为学习对象.在本文中,一些基本的操作将不再介绍,只会介绍最为常用的命令以及设置,操作系统为Ubuntu ...
- jquery的 $(function(){ }) = $(document).ready(function(){ }) ,及页面的加载顺序
document.ready和onload的区别:一.JavaScript文档加载完成事件页面加载完成有两种事件一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二.是onloa ...
- 常用sql时间字符转化
这边主要用到2个函数 convert() cast() cast是对数据字符类型的转化,例如: cast(date as datetime) 这样就将date字段转化成为时间类型了 因为常用到 ...
- WInform启动另一个项目传值
背景:从A项目中登陆后,跳转到B项目的某个页面(B不再登陆). A项目启动进程: public Form1() { InitializeComponent(); } #region 调用进程 [Dll ...
- 本地安装gem install --local redis-stat-0.4.13.gem
因为主机环境不能联外网,悲哀,所以只能想办法下载包,上传到主机来安装 环境:el6.x86_64 1. gem 安装[http://centos.ustc.edu.cn/centos/6/os/x86 ...
- NavigationBar的简单设置
http://blog.csdn.net/hufeng825/article/details/7643532#) .Label属性设置 titleLabel = [[UILabel alloc] in ...
- How to add EDT relation table[AX2012]
setp 1. First create New Edit. setp 2.Create New Table First Table Name is NParentRel then drag and ...
- mac常用设置
1.修改mac主机名 系统偏好设置->共享->电脑名称 ,编辑就可以了. sudo scutil --set HostName hostname 这个是修改主机名 sudo scutil ...
- hadoop的核心思想
hadoop的核心思想 1.1.1. hadoop的核心思想 Hadoop包括两大核心,分布式存储系统和分布式计算系统. 1.1.1.1. 分布式存储 为什么数据需要存储在分布式的系统中哪,难道单一的 ...
- IOS开发经验分享
一些IOS开发的心得: 1) [Multiple Threads] IOS多线程注意, 所有的UI操作都必须在主线程上: Any code that will update the UI should ...