Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 5513   Accepted: 2319

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

求二分图最大独立集。给字符串都做好映射,然后根据题目中条件,把可能组CP的人之间连边,跑匈牙利算法就行。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<vector>
#include<map>
using namespace std;
const int mxn=;
struct stu{
int h;//高度
bool se;//性别
int m,sp;
}a[mxn];
map<string,int> mpm,mpsp;
vector<int>e[mxn];
int mcnt=,spcnt=;
int n;
//
int link[mxn],vis[mxn];
//
void clear(){
mpm.clear();
mpsp.clear();
memset(a,,sizeof a);
memset(link,,sizeof link);
for(int i=;i<=n;i++) e[i].clear();
mcnt=spcnt=;
}
bool dfs(int s){//匈牙利算法
int i,j;
for(i=;i<e[s].size();i++){
int v=e[s][i];
if(!vis[v]){
vis[v]=;
if(!link[v] || dfs(link[v])){
link[v]=s;
return ;
}
}
}
return ;
}
void calc(){
int i,j;
int ans=n;
for(i=;i<=n;i++){
if(a[i].se){
memset(vis,,sizeof vis);
if(dfs(i))ans--;
}
}
printf("%d\n",ans);
}
int main(){
int T;
scanf("%d",&T);
char sex[],music[],sport[];
while(T--){
scanf("%d",&n);
clear();
int i,j;
for(i=;i<=n;i++){
cin>>a[i].h>>sex>>music>>sport;
if(sex[]=='M') a[i].se=;
else a[i].se=;
if(!mpm.count(music)){//映射音乐
mcnt++;
mpm[music]=mcnt;
}
a[i].m=mpm[music];
if(!mpsp.count(sport)){//映射运动
spcnt++;
mpsp[sport]=spcnt;
}
a[i].sp=mpsp[sport];
// printf("test : %d %d %d\n",a[i].se,a[i].m,a[i].sp);
}
for(i=;i<n;i++)
for(j=i+;j<=n;j++){
if((abs(a[i].h-a[j].h)<=)&&(a[i].se!=a[j].se)&&(a[i].m==a[j].m)&&(a[i].sp!=a[j].sp)){//连边条件
e[i].push_back(j);
e[j].push_back(i);
}
}
calc();
}
return ;
}

POJ2771 Guardian of Decency的更多相关文章

  1. Guardian of Decency(二分图)

    Guardian of Decency Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  2. Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游

    /** 题目:Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游 链接:https://vjudge.net/problem/UVA ...

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

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

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

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

  5. uva 12083 Guardian of Decency (二分图匹配)

    uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...

  6. poj——2771 Guardian of Decency

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

  7. UVALive 3415 Guardian of Decency(二分图的最大独立集)

    题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...

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

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

  9. UVAlive3415 Guardian of Decency(最大独立集)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34831 [思路] 二分图的最大独立集. 即在二分图中选取最多的点, ...

随机推荐

  1. 1061: [Noi2008]志愿者招募

    Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 5742  Solved: 3449[Submit][Status][Discuss] Descript ...

  2. 爬虫学习(五)——使用handler管理器对象进行数据爬取的步骤

    # 使用管理器对象进行爬取数据的步骤 import urllib.requesturl = "https://www.baidu.com/"# 创建handler的管理器对象han ...

  3. Python 文件读写 文件和路径

    1.在Windows上,使用倒斜杆作为文件夹之间的分隔符,在Linux上,使用正斜杠作为路径分隔符.在编写Python脚本时,可以os.path.join()函数来处理 在Windows环境下命令如下 ...

  4. 微信小程序 onLoad 函数

    小程序注册完成后,加载页面,触发onLoad方法. 页面载入后触发onShow方法,显示页面. 首次显示页面,会触发onReady方法,渲染页面元素和样式,一个页面只会调用一次. 当小程序后台运行或跳 ...

  5. 数据结构-单链表(Linked List)

    #include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 10 #define LISTINCREMENT 1 ...

  6. mysql同步故障解决

    故障现象:Slave_SQL_Running: No Slave状态:mysql> show slave status\GSlave_IO_Running: YesSlave_SQL_Runni ...

  7. Linux下 导入导出数据库

    1.怎么找到mysql下的bin? 1.1首先我在网上百度了一些Linux下如何导入导出数据.基本都是用mysqldump命令,但是如果没有到指定目录 下,执行这个命令是没有用的.一开始我还以为要在m ...

  8. flex布局之flex-grow和flex-shrink如何计算

    此文已由作者张含会授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 关于盒模型布局 如何实现两栏布局? (表格) 流式, 浮动, 定位 如何选择? 流式 > 浮动 > ...

  9. IOS开发---菜鸟学习之路--(二十一)-利用正则表达式解析URL获取其中的参数

    因为项目需要解析URL当中参数的部分,在网上搜索了一下都没有相关的资料. 然后就自己写了一个 其实我就是通过正则表达式来处理URL 进行解析的 好了直接上代码吧 也是非常的简单,大家拷贝过去就可以使用 ...

  10. 67、activity中调用fragment内部自定义的方法

    fragment: /** * author: Created by zzl on 15/11/19. */ @SuppressLint("validFragment") publ ...