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. 正则表达式(Regular Expression, RegEx)学习入门

    1. 概述 正则表达式(Regular Expression, RegEx)是一种匹配模式,描述的是一串文本的特征. 正如自然语言中高大.坚固等词语抽象出来描述事物特征一样,正则表达式就是字符的高度抽 ...

  2. Word 分栏页码,一个页面两个不同页码的设置

    1. 前言 在一些报纸.杂志中,我们可以见到各种各样的排版风格效果,其中有一种效果是一个页面设置了两栏,并且每栏下面都有不同的页码,那么,这种效果是如何实现的呢?这种页码在Word中默认页码样式中是没 ...

  3. Visual studio 2010(VS2010) 安装MSDN方法

    首先保证VS2010已经安装完毕 1.解压VS2010的安装文件(ISO),会看到ProductDocumentation文件夹,该文件夹下即为MSDN. 2.启动vs2010,点击"帮助& ...

  4. 搭建apache2.4+php7+mysql+phpmyadmin

    apache2.2不支持php7,会报错 cannot load php7apache2_4.dll into server 前排提示:保证安装文件夹和我的一致可以省事很多哦 下载地址 下载apach ...

  5. Python开发【第三章】:编码转换

    一.字符编码与转码 1.bytes和str 之前有学过关于bytes和str之间的转换,详细资料->bytes和str(第四字符串) 2.为什么要进行编码和转码 由于每个国家电脑的字符编码格式不 ...

  6. java实现带过期时间的缓存

    private static ScheduledExecutorService swapExpiredPool = new ScheduledThreadPoolExecutor(10); priva ...

  7. MySQL AND 和 OR 联合使用带来的坑

    MySQL 基础篇 三范式 MySQL 军规 MySQL 配置 MySQL 用户管理和权限设置 MySQL 常用函数介绍 MySQL 字段类型介绍 MySQL 多列排序 MySQL 行转列 列转行 M ...

  8. (九)shiro之web集成

    Url 匹配方式? 匹配一个字符 /admin? 可以匹配/admin1 或者/admin2 但是不能匹配/admin12 或者/admin* 匹配零个或者一个或者多个字符 /admin* 可以匹配 ...

  9. 奇妙的算法【10】TX--有效号码、最,小耗时、最小差值、差值输出、异或结果

    昨晚刚刚写的几道算法题,难度也还行,就是全部AC有些困难,当时第一题AC.第二题AC 60%,第四题AC 40%,第五题没有时间写完了,这个应该全部AC了:其中第三题没有写出来 1,是否存在符合规范的 ...

  10. .net core +gogs + jenkins +docker自动化发布、部署

    1.首先,安装docker,不多bb 2.我们采用docker的方式安装jenkins,同时将宿主机的docker挂载到docker安装的jenkins里面,可能有点拗口.说白了就是 就是要让jenk ...