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. jquery 广告轮播图

    轮播图 /*轮播图基本功能: * 1图片切换 * 1.1图片在中间显示 * 1.2图片淡入淡出 * 2左右各有一个按钮 * 2.1点击左按钮,图片切换上一张 * 2.2点击右按钮,图片切换下一张 * ...

  2. diy操作系统 附录:gcc栈帧开启与关闭

    在gcc命令行参数中可以使用-fno-omit-frame-pointer来开启栈帧的使用,或者使用-fomit-frame-pointer选项来关闭. 然而,也可以针对某一个函数进行配置方法如下,这 ...

  3. chrome 调试 ios h5

    1,安装itunes, 否则无法识别iphone设备 2,开启调试模式 ,打开 iPhone 依次进入 设置 > Safari > 高级 > Web 检查 > 启用 3,下载 ...

  4. 使用Duilib开发Windows软件(1)——HelloWorld

    我使用的是网易版本: https://github.com/netease-im/NIM_Duilib_Framework 时间是2019-11-28,作者最新的提交如下图: 运行官方示例程序 下载完 ...

  5. Geometers Anonymous Club CodeForces - 1195F (闵可夫斯基和)

    大意: 给定$n$个凸多边形, $q$个询问, 求$[l,r]$内闵可夫斯基区间和的顶点数. 要用到一个结论, 闵可夫斯基和凸包上的点等于向量种类数. #include <iostream> ...

  6. 深度挖坑:从数据角度看人脸识别中Feature Normalization,Weight Normalization以及Triplet的作用

    深度挖坑:从数据角度看人脸识别中Feature Normalization,Weight Normalization以及Triplet的作用 周翼南 北京大学 工学硕士 373 人赞同了该文章 基于深 ...

  7. C#xml泛型序列化

    using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Web ...

  8. springboot中使用验证码kaptcha

    1.pom.xml引入kaptcha所需要的jar包 <!-- 验证码 --> <dependency> <groupId>com.github.penggle&l ...

  9. mysql cmd命令行 创建数据库 表 基础语句

    一.连接MYSQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1. 连接到本机上的MYSQL. 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u roo ...

  10. flume 1.7在windows下的安装部署与测试运行

    一.安装 安装java,配置环境变量. 安装flume,下载地址,下载后直接解压即可. 二.运行 创建配置文件:在解压后的文件 apache-flume-1.7.0-bin\conf下创建一个exam ...