题目链接:

http://poj.org/problem?id=2771

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
 /*
问题
输入n个人的信息,如果他们满足几个条件就视为存在成为一对的关系,求不能成为一对的最大子独立集的顶点个数 解题思路
图论的题很绕,让我们理清关系,求最大子图,就是挑几个人,他们相互之间都存在一种不能成为一对的关系,最多有多少人
做图的时候,将存在能成为一对的关系的置为1,否则都置为0,跑一边匈牙利算法得到最大匹配数
那么顶点数n减去最大匹配数就是最大子独立集的个数了。
*/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath> using namespace std;
const int maxn=;
int n,e[maxn][maxn],fn,mn;
int cx[maxn],cy[maxn];
int book[maxn];
struct PER{
int age;
string sex,music,sport;
}fper[maxn],mper[maxn]; int ok(struct PER a, struct PER b);
int maxmatch();
int dfs(int u); int main()
{
int T,i,j;
int x;
char s1[],s2[],s3[];
scanf("%d",&T);
while(T--){
scanf("%d",&n);
fn=mn=;
for(i=;i<n;i++){
scanf("%d%s%s%s",&x,s1,s2,s3);
if(strcmp(s1,"F") == ){
fper[fn].age=x;
fper[fn].sex=s1;
fper[fn].music=s2;
fper[fn].sport=s3;
fn++;
}
else{
mper[mn].age=x;
mper[mn].sex=s1;
mper[mn].music=s2;
mper[mn].sport=s3;
mn++;
}
} memset(e,,sizeof(int)*maxn*maxn);
for(i=;i<mn;i++){
for(j=;j<fn;j++){
if(ok(mper[i],fper[j]))
e[i][j]=;
}
}
printf("%d\n",n-maxmatch());
}
return ;
} int ok(struct PER a, struct PER b){
if(abs(a.age - b.age) > )
return ;
if(a.sex == b.sex)
return ;
if(a.music != b.music)
return ;
if(a.sport == b.sport)
return ; return ;
} int dfs(int u)
{
for(int i=;i<fn;i++){
if(book[i] == && e[u][i]){
book[i]=; if(cy[i] == - || dfs(cy[i])){
cx[u]=i;
cy[i]=u;
return ;
}
}
}
return ;
} int maxmatch()
{
int i;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
int ans=;
for(i=;i<mn;i++){
if(cx[i] == -){
memset(book,,sizeof(book));
if(dfs(i)) ans++;
}
}
return ans;
}

POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)的更多相关文章

  1. poj——2771 Guardian of Decency

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

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

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

  3. poj 2771 Guardian of Decency 解题报告

    题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距   ...

  4. POJ 2771 Guardian of Decency (二分图最大点独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6133   Accepted: 25 ...

  5. UVA 12083 POJ 2771 Guardian of Decency

    /* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...

  6. poj 2771 Guardian of Decency(最大独立数)

    题意:人与人之间满足4个条件之一即不能成为一对(也就说这4个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...

  7. POJ 2771 Guardian of Decency

    http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40  ②同性 ③喜欢 ...

  8. POJ 2771 Guardian of Decency(求最大点独立集)

    该题反过来想:将所有可能发生恋爱关系的男女配对,那么可以带出去的人数应该等于这个二分图的最大独立集 先要做一下预处理,把不符合要求的双方先求出来, company[i][j]表示i.j四个标准都不符合 ...

  9. UVALive3415 Guardian of Decency —— 最大独立集

    题目链接:https://vjudge.net/problem/UVALive-3415 题解: 题意:选出尽可能多的人, 使得他(她)们之间不会擦出火花.即求出最大独立集. 1.因为性别有男女之分, ...

随机推荐

  1. yum-本地源配置(CentOS7)

    服务器版本查看:# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) 一.挂载ISO文件: 1.ISO镜像下载网站:网易镜像: ...

  2. Android-Java单例模式

    今天我们来说说一个非常常用的模式,单例模式,单例模式让某个类中有自己的实例,而且只实例化一次,避免重复实例化,单例模式让某个类提供了全局唯一访问点,如果某个类被其他对象频繁使用,就可以考虑单例模式,以 ...

  3. 个人作业四--Alpha阶段个人总结

    一.个人总结 在alpha 结束之后, 每位同学写一篇个人博客, 总结自己的alpha 过程: 请用自我评价表:http://www.cnblogs.com/xinz/p/3852177.html 有 ...

  4. linux常用命令(二)文件上传下载及软件安装

    1.上传下载工具安装 (1)WINDOWS 到linux的文件上传及下载: windows下打开secureCRT,通过SSH连到⾄至远程linux主机:上传下载工具安装命令:yum -y insta ...

  5. Mybatis-generator插件,用于自动生成Mapper和POJO

    后台环境为springboot+mybatis. 步骤一:添加mybatis环境 <dependency> <groupId>mysql</groupId> < ...

  6. OCP考试062题库出现大量新题-19

    choose three Which three statements are true about Oracle Data Pump? A) Oracle Data Pump export and ...

  7. MariaDB 用户与权限管理(12)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  8. es6新增Math方法

    Math.trunc()  用于去除一个数的小数部分,只返回整数部分 Math.trunc(4.1) // 4 Math.trunc(4.9) // 4 Math.trunc(-4.1) // -4 ...

  9. Git 本地操作

    版权声明:数学是研究世界的本质,自然科学是研究上帝的意志,而计算机则是揣摩屌丝人类的意志   目录(?)[-] 命令 git config 增删改查 init clone add commit sta ...

  10. 题解 P2146 【[NOI2015]软件包管理器】

    题目大意 ​ 给你一棵树, 求一点到根的路径上有多少个未标记点并全标记, 和询问一个点的子树内有多少已标记点和撤销标记 解题方法 1: install 操作 ​ 这个操作是求一点到根的路径上有多少个未 ...