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 ...
随机推荐
- Z-Stack学习笔记
Technorati 标签: Z-Stack profile 1. 栈配置profile 栈参数的集合需要被配置为一定的值,连同这些值在一起被称之为栈配置.ZigBee联盟定义了这些由栈配置组成的栈参 ...
- 第一个APP 时钟
// ViewController.h // IOS310803 // // Created by 张艳锋 on 15/8/3. // Copyright (c) 2015年 zyf. All ...
- background-clip 背景图片做适当的裁剪
background-clip 用来将背景图片做适当的裁剪以适应实际需要. 语法: background-clip : border-box | padding-box | content-box | ...
- PHP实现链式操作的原理
在一个类中有多个方法,当你实例化这个类,并调用方法时只能一个一个调用,类似: db.php <?php class db{ public function where() { //code he ...
- extjs的combobox的用法
可以用javascript的数组作为数据源,也可以用json作为数据源: 1.用javascript数组 var CountryCode = [ ['93','Afghanistan(93)'], [ ...
- Python开发【第一篇】Python基础之装饰器
写代码要遵循开发封闭原则,虽然在这个原则是用的面向对象开发,但是也适用于函数式编程,简单来说,它规定已经实现的功能代码不允许被修改,但可以被扩展,即: 封闭:已实现的功能代码块开放:对扩展开发 #s2 ...
- 安装mysql 5.5.14 报错
提示cmake nod foundyum install cmake 原因是曾经服务器安装过mysql数据库Installing MySQL system tables...101223 14:28: ...
- 【go】sdk + idea-plugin 开发工具安装
http://golang.org/doc/install/source 第一步:windows 安装 git第二步$ git clone https://go.googlesource.com/go ...
- Msys+Mingw在手 妙用在心!
1 缘起 平时在一些c++群面,看见很多大学十分努力的学习c++/MFC ,看见在编程语言百花争芳的时候,C/C++还是很有很有魅力.估计很多初学者使用都是window下的visual stdio 开 ...
- 在MAC平台下编译Ngnix ,由于MD5算法不能编译通过 解决办法
近期想学习Ngnix 代码,前些日子,对”自己下手狠一次“, 买了MAC 本. 所以想在Mac 上编译,是必须的,不然对不起自己的内心. 不巧遇到了MD5算法编译的问题 src/core/ngx_cr ...