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 ;
}

最新文章

  1. MySQL 安装 + 精简 + 配置
  2. [python](爬虫)如何使用正确的姿势欣赏知乎的“长得好看是怎样一种体验呢?”问答中的相片
  3. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
  4. JS截取字符串常用方法
  5. 一键安装GitLab7
  6. js隐藏
  7. Oracle hextoraw和rawtohex
  8. onethink加密解密函数
  9. C# - string 转为 DateTime(自定义)
  10. MemCachedClient数据写入的三个方法
  11. VS发布网站步骤(先在vs上发布网站到新的文件夹,然后挂到iis上面)
  12. jquery的2.0.3版本源码系列(3):96行-283行,给JQ对象,添加一些方法和属性
  13. 关于linux下的嵌入式文件系统以及flash文件系统选择
  14. 实验与作业(Python)-05 程序的控制结构
  15. IntelliJ IDEA最新破解版2018.3.1(附2018.2.2 完美破解教程)
  16. CentOS中无法使用setup命令 -bash:setup: command not found
  17. hadoop 组件 hdfs架构及读写流程
  18. eclipse里面的时间错误,比电脑系统时间慢了8个小时
  19. MVC架构思想
  20. 永久解决delphi 2010不能2次启动问题

热门文章

  1. 28. Brackets安装angularjs插件
  2. Git 操作笔记
  3. java command not found
  4. Vbox下创建Linux和Windows的共享文件夹
  5. MOOC使用心得
  6. ajax和axios请求本地json数据对比
  7. 数据持久化(六)之Using CoreData with MagicalRecord
  8. Android自己定义视图(一):带下划线的TextView
  9. Eclipse中JDK的配置
  10. 机器学习Python实现AdaBoost