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. 在Linux终端使用W3M浏览器下载文件

    在Linux终端使用W3M浏览器下载文件 W3M 是3个基于Linux系统命令行的WEB网站浏览工具(w3m/Links/Lynx) 对于需要验证cookie 和来源的页面,比如163的超大附件,直接 ...

  2. 从Linux系统内存逐步认识Android应用内存

    总述 Android应用程序被限制了内存使用上限,一般为16M或24M(具体看系统设置),当应用的使用内存超过这个上限时,就会被系统认为内存泄漏,被kill掉.所以在Android开发时,管理好内存的 ...

  3. 三段式状态机 [CPLD/FPGA]

    状态机的组成其实比较简单,要素大致有三个:输入,输出,还有状态. 状态机描述时关键是要描述清楚前面提高的几个状态机的要素,即如何进行状态转移:每个状态的输出是什么:状态转移是否和输入条件相关等. 有人 ...

  4. Select 选择算法 - 编程珠玑(续) 笔记

    Select 算法 I 编程珠玑(续)介绍的 Quickselect 算法 选择 N 个元素中的第 K 小(大)值,是日常场景中常见的问题,也是经典的算法问题. 选取 N 个元素的数组的中的第 K 小 ...

  5. toggleClass slideToggle

    $("#wrapper").toggleClass("toggled"); $("p").slideToggle(1000); demo: ...

  6. org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1

    不能加载或找不到 org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1 经查证,是mybatis-spring-xxx.jar 这个版 ...

  7. MySQL Pool

    创建连接池 function SqlPool() { this.flag = true;//是否连接过 this.pool = mysql.createPool({ host : 'localhost ...

  8. 【RHEL7/CentOS7基本配置】

    目录 @ 相比于6.x的版本,Rhel7/CentOS7增加或改进了以下7大特性. 1.身份管理 kerberos的跨平台信任机制:kerberos将完全兼容微软活动目录,实现完全使用活动目录进行认证 ...

  9. vue踩坑- 报错npm ERR! cb() never called!

    在vue项目中引入饿了么elementUI组件的步骤之中,出现以下的错误: D:\my-project-first>npm i element-ui -S Unhandled rejection ...

  10. 局域网内机器不能对ping问题

    局域网内有台A机器能ping同其他机器,但其他机器不能ping A机器.属于同一个网段 解决办法: cmd->msconfig->常规->诊断启动,仅加载基本设备和服务. 重启后试下 ...