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 platform设备简介
Technorati 标签: Linux platform Linux在2.6内核中,针对一系列设备驱动,提供新的管理框架,成为platform机制,推出的目的,在于隔离驱动的资源和实现,使得 ...
- Win8 URI 方案 ms-appX 用法大全
ms-appdata://可以引用来自应用的本地.漫游和临时数据文件夹中的应用文件ms-appdata:///local/hello/logo.png ms-appx://可以引用来自应用包的应用文件 ...
- javascript 逻辑运算符
javascript逻辑运算符 NOT(!) AND(&&) OR(||) NOT(!) 返回值的类型一定是Boolean值的 运算数也是Boolean值 返回值是:与相反的boole ...
- Centos6.4版本下搭建LAMP环境
Centos6.4版本下搭建LAMP环境 配置yum mkdir/mnt/cdrom mount/dev/cdrom /mnt/cdrom 装载光盘 vi /etc/yum.repos.d/Cent ...
- JavaScript ==和===
== : 值等 === :恒等(引用等) ref: http://blog.csdn.net/wang171838/article/details/8554305 JavaScript支持“=”.“ ...
- AngularJS(11)-API
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android listview viewpager解决冲突 滑动
Android listview viewpager滑动 跳动 冲突解决 ListView中嵌套ViewPage有或者滑动手势冲突解决 在listview 上使用 addHeaderView 在第 ...
- 反编译APK终结教程
现在来教大家如何由网上下载的Android应用反编译为源码.如果你感兴趣,就来看一看吧.前提是你的电脑得已经配置好了java环境,如果没有配置好的话,下面我会附带一提,如果你还是不懂的话,那就上网搜一 ...
- 虚拟局域网VLAN
6.5.1配置路由器广域网端口的PPP封装 (1)配置路由器A: Router>enable Router#config Router_config#hostname Router-A Rout ...
- JavaScript中使用console调试程序的坑
上DEMO a = {key1: [1, 2], 'key2': {'key4': '11'}, 'key3': [1, 2]} console.info(1,a) a.key2.key4 = '22 ...