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

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 5932   Accepted: 2463

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

Source

 
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int t,n,h,ans; int sumb,sumg;
struct Node
{
int heigh;
char music[],sport[];
}boy[N],girl[N]; int head[N],sumedge;
struct Edge
{
int u,v,next;
Edge(int u=,int v=,int next=):
u(u),v(v),next(next){}
}edge[N*N];
void ins(int u,int v)
{
edge[++sumedge]=Edge(u,v,head[u]);
head[u]=sumedge;
} int vis[N],match[N];
bool DFS(int x)
{
for(int i=head[x];i;i=edge[i].next)
{
int v=edge[i].v;
if(vis[v]) continue;
vis[v]=;
if(!match[v]||DFS(match[v]))
{
match[v]=x;
return true;
}
}
return false;
} void init()
{
ans=sumedge=sumb=sumg=;
memset(boy,,sizeof(boy));
memset(girl,,sizeof(girl));
memset(head,,sizeof(head));
memset(match,,sizeof(match));
scanf("%d",&n);
} int main()
{
scanf("%d",&t);
for(;t--;)
{
init();char xb;
for(int h,i=;i<=n;i++)
{
scanf("%d",&h);cin>>xb;
if(xb=='F') boy[++sumb].heigh=h,scanf("%s%s",boy[sumb].music,boy[sumb].sport);
else girl[++sumg].heigh=h,scanf("%s%s",girl[sumg].music,girl[sumg].sport);
}
for(int i=;i<=sumb;i++)
for(int j=;j<=sumg;j++)
if(abs(boy[i].heigh-girl[j].heigh)<=&&!strcmp(boy[i].music,girl[j].music)&&strcmp(boy[i].sport,girl[j].sport))
ins(i,j);
for(int i=;i<=sumb;i++)
{
memset(vis,,sizeof(vis));
if(DFS(i)) ans++;
}
printf("%d\n",n-ans);
}
return ;
}

POJ——T2271 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 (二分图最大点独立集)

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

  4. POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)

    题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...

  5. POJ 2771 Guardian of Decency

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

  6. poj 2771 Guardian of Decency 解题报告

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

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

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

  8. UVA 12083 POJ 2771 Guardian of Decency

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

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

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

随机推荐

  1. webpack03

    index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  2. thinkphp里面的or查询

    thinkphp里面的or查询 whereOr 方法 使用whereOr 方法进行OR 查询: Db::table('think_user') ->where('name','like','%t ...

  3. 流量数据iftop命令

    yum install flex byacc libpcap ncurses ncurses-devel libpcap-devel tar zxvf iftop-0.17.tar.gz cd ift ...

  4. 初学Larevel 2014-08-21 11:24 90人阅读 评论(0) 收藏

    添加第一个路由时就遇到了 404错误,查了一下说要这样才能 版权声明:本文为博主原创文章,未经博主允许不得转载.

  5. 在C# 获取当前应用网址

    /// <summary>        /// 获取当前应用网址        /// </summary>        /// <returns></r ...

  6. 在Windows下如何创建虚拟环境(默认情况下)

    很多小伙伴平时在使用Python的时候,有的项目需要使用Python2来进行开发,有的项目则是需要Python3来进行开发.当不清楚怎么分开环境的时候,此时两个环境开始打架,彼此傻傻分不清楚.虚拟环境 ...

  7. 重大漏洞:Bitlocker成摆设,多款固态硬盘硬件加密均可被绕过

    荷兰拉德堡德大学的两名研究人员日前发表论文,描述了固态硬盘流行加密软件Bitlocker中的关键漏洞.固态硬盘需要口令来加密和解密其上存储的内容,但该口令可以被绕过. 荷兰拉德堡德大学的两名研究人员日 ...

  8. Python的主要库

    本文在Creative Commons许可证下发布 市面上的分析工具大致分为两大类,菜单式的工具和命令行式的工具.前者适合于初学入门,类似于跟团旅游,提供了固定的路线.分析套路比较固定化,点几下鼠标就 ...

  9. git hub在windows上的使用

    每次使用都需要查找,太麻烦了. 转过来自己用! git hub在windows上的使用 一. 首先安装客户端 Git for Windows. 按提示默认安装后,进入git bash(桌面上) 首先检 ...

  10. CentOS 7上安装gitlab-runner

    1.yum install gitlab-runner -y 2.Registering Runners a.Run the following command: gitlab-runner regi ...