题目链接:

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. iOS 使用代码创建约束,实现自动布局

    ///与下面约束对象属性截图相对应//使用Auto Layout约束,禁止将Autoresizing Mask转换为约束 [self.funcView setTranslatesAutoresizin ...

  2. 有人在用fastReport作报表时处理过字体自动缩小的问题吗,怎么做

    有人在用fastReport作报表时处理过字体自动缩小的问题吗,怎么做  我来答   浏览 49 次 1个回答 #吃瓜大会# Angelababy演技被吐槽, 你觉得她的演技怎么样? 最佳答案 热心 ...

  3. python 操作mysql数据库之模拟购物系统登录及购物

    python 操作mysql数据库之模拟购物系统登录及购物,功能包含普通用户.管理员登录,查看商品.购买商品.添加商品,用户充值等. mysql 数据库shop 表结构创建如下: create TAB ...

  4. C#知识点提炼期末复习专用

    根据内部消息称:有三类题型:  程序阅读题:2题  简答题:2题 (主要是对概念的考查)  编程题:暂定2-3题 复习要点: .net framework 通用语言开发环境..NET基础类库..NET ...

  5. 前端基础-html 列表标签,表格标签,表单标签

    一.列表标签 1.ul(无序列表)标签 ul(unordered list)无序列表,ul下的子元素只能是li(list item),如下示例: <ul> <li>第一项< ...

  6. Swift 里 Set (三)Inspecting a Set

    isEmpty /// A Boolean value that indicates whether the set is empty. @inlinable public var isEmpty: ...

  7. maven封装jar包遇到的问题

    使用eclipse编译后可以生成jar包,使用mvn clean package指令打包报错,错误如下:No compiler is provided in this environment. Per ...

  8. [Leetcode]下一个更大元素II

    题目 给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素.数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大的数,这意味着你应该循环地 ...

  9. 【sping揭秘】11、Java 平台上的AOP实现机制

    动态代理 Jdk1.3只有引入的动态代理机制,可以再运行期间,为相应的接口(必须得有接口)动态生成对应的代理对象 基于以上问题,我们可以将横切关注点逻辑封装到动态代理的invocationhandle ...

  10. swiper4-vue 不使用loop,由最后一张跳到第一张

    <template> <div class="swiper-box"> <div class="swiper-container" ...