Problem Description
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude this possibility, he has made some rules that he thinks indicates a low probability two persons will become a couple: 
Their height differs by more than 40 cm. 
They are of the same sex. 
Their preferred music style is different. 
Their favourite sport is the same (they are likely to be fans of different teams and that would result in fighting).

So, for any two persons that he brings on the excursion, they must satisfy at least one of the requirements above. Help him find the maximum number of persons he can take, given their vital information.

Input
The first line of the input consists of an integer T ≤ 100 giving the number of test cases. The first line of each test case consists of an integer N ≤ 500 giving the number of pupils. Next there will be one line for each pupil consisting of four space-separated data items: 
an integer h giving the height in cm; 
a character 'F' for female or 'M' for male; 
a string describing the preferred music style; 
a string with the name of the favourite sport.

No string in the input will contain more than 100 characters, nor will any string contain any whitespace.

Output
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.

Sample Input
2
4
35 M classicism programming
0 M baroque skiing
43 M baroque chess
30 F baroque soccer
8
27 M romance programming
194 F baroque programming
67 M baroque ping-pong
51 M classicism programming
80 M classicism Paintball
35 M baroque ping-pong
39 F romance ping-pong
110 M romance Paintball

Sample Output
3
7

题意:老师带学生去旅游,但是担心学生会发生恋爱关系,因此带出去的学生彼此间要满足以下条件中的一个:(1.身高相差 40cm 以上、2.同性、3.喜欢音乐风格不同、4.喜欢运动相同),求最多能带多少学生出去

思路:通过公式:二分图最大独立集=顶点数-二分图最大匹配。先求相爱的最大匹配数。

二分图最大独立集=顶点数-二分图最大匹配

独立集:图中任意两个顶点都不相连的顶点集合。

AC代码:

 #include<algorithm>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<string.h> using namespace std;
#define maxn 888
int n,m;
vector<int> v[maxn];
int vis[maxn];
int match[maxn];
struct str{
int h;
string shengfen;
string mus;
string sport;
}st[maxn];
bool ok(str a,str b){
if(abs(a.h-b.h)<=&&a.shengfen!=b.shengfen&&a.mus==b.mus&&a.sport!=b.sport)
return ;
else
return ;
}
int dfs(int u){
for(int i=;i<v[u].size();i++){
int temp=v[u][i];
if(vis[temp]==){
vis[temp]=;
if(match[temp]==||dfs(match[temp])){
match[temp]=u;
return ;
}
}
}
return ;
}
int main(){
int _;cin>>_;
while(_--){
scanf("%d",&n);
for(int i=;i<=n;i++)
v[i].clear();
for(int i=;i<=n;i++){
// cin>>st[i].h
scanf("%d",&st[i].h);
cin>>st[i].shengfen>>st[i].mus>>st[i].sport;
//scanf("%s%s%s",st[i].shengfen,st[i].mus,st[i].sport);
}
for(int i=;i<=n;i++){
for(int j=+i;j<=n;j++){
if(ok(st[i],st[j])){
v[i].push_back(j);
v[j].push_back(i);
}
}
}
for(int i=;i<=n;i++)
match[i]=;
// memset(match,0,sizeof(match));
int ans=;
for(int i=;i<=n;i++){
//memset(vis,0,sizeof(vis));
for(int i=;i<=n;i++)
vis[i]=;
if(dfs(i))
ans++;
}
//cout<<ans<<endl;
int res=n-ans/;
printf("%d\n",res); }
return ;
}

Guardian of Decency POJ - 2771 【二分匹配,最大独立集】的更多相关文章

  1. POJ 2771 二分图(最大独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5244   Accepted: 21 ...

  2. HDU - 1068 Girls and Boys(二分匹配---最大独立集)

    题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...

  3. poj 2446 (二分匹配)

    题意:除了所给的一些点外,问能不能用1*2的矩形覆盖所有的点,矩形间不能重叠. 思路:简单二分匹配,,,,,,, #include<stdio.h> #include<string. ...

  4. hdu 4169 二分匹配最大独立集 ***

    题意:有水平N张牌,竖直M张牌,同一方向的牌不会相交.水平的和垂直的可能会相交,求最少踢出去几张牌使剩下的牌都不相交. 二分匹配 最小点覆盖=最大匹配. 链接:点我 坐标点作为匹配的端点 #inclu ...

  5. hdu3829 二分匹配 最大独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...

  6. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集

    m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...

  7. POJ 1498[二分匹配——最小顶点覆盖]

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1498] 题意:给出一个大小为n*n(0<n<100)的矩阵,矩阵中放入m种颜色(标号为1 ...

  8. POJ 2771 Guardian of Decency 【最大独立集】

    传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  9. poj——2771 Guardian of Decency

    poj——2771    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5916   ...

随机推荐

  1. Qt程序开机自动运行

    一.写入注册表需要管理员权限 1.开发中生成并运行程序需要写入注册表时,应该以管理员权限打开项目: 2.点击程序运行需要写入注册表,则应该以管理员权限打开此程序. 二.实现 void MoreSetW ...

  2. Excel关联匹配函数

    1.=VLOOKUP (lookup_value, table_array, col_index_num, [range_lookup]) ​ lookup_value 相当于python中的键,用来 ...

  3. stal 安装

    1.1 准备实验环境: 安装系统 1)硬件配置如下 2) 先把光标放到”install CentOS 7”,按 Tab键编辑内核参数,添加 (net.ifnames=0 biosdevname=0) ...

  4. 浅谈人脸识别中的loss 损失函数

    浅谈人脸识别中的loss 损失函数 2019-04-17 17:57:33 liguiyuan112 阅读数 641更多 分类专栏: AI 人脸识别   版权声明:本文为博主原创文章,遵循CC 4.0 ...

  5. PHP迭代生成器---yield

    1.迭代生成器 生成器的核心是一个yield关键字,一个生成器函数看起来像一个普通的函数,不同的是:普通函数返回一个值,而一个生成器可以yield生成许多它所需要的值.生成器函数被调用时,返回的是一个 ...

  6. 电子口岸 打开“退税联打印”时,PDF界面无法显示

    电子口岸 打开“退税联打印”时,PDF界面无法显示 咨询0571-95198 : IE要在8-10间,系统 要Win7 32B ---------------------参考------------- ...

  7. 解析Illumina+PacBio组装策略

    解析Illumina+PacBio组装策略 (2016-12-08 13:21:58) 转载▼     基于Illumina和PacBio平台的“二加三”组装策略,巧妙的融合了PacBio平台超长读长 ...

  8. nlopt 二次优化

    /* * main.c * * Created on: Oct 9, 2018 * Author: lgh */ #include <stdio.h> #include <math. ...

  9. Docker启动Elasticsearch报错java.nio.file.AccessDeniedException

    报错信息 Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes 问题分析 表面上是说容 ...

  10. springboot启动流程(九)ioc依赖注入

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 在前面的几篇文章中,我们多次提到这么一个转化过程: Bean配置 --> Bean ...