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. JavaScript方法中this关键字使用注意

    问题来源 本文是基于廖雪峰老师JavaScript课程中的方法一节以及阮一峰老师JavaScript 的 this 原理 所记. 首先,我们了解一下JavaScript中的方法:在一个对象中绑定函数, ...

  2. 二叉树(dfs)

    样例输入: 5        //下面n行每行有两个数 2 3    //第i行的两个数,代表编号为i的节点所连接的两个左右儿子的编号. 4 5 0 0    // 0 表示无 0 0 0 0   样 ...

  3. 第 8 章: 模块, 包与分发---Word

    第八章: 模块, 包 与 分发 描述: 大型Python程序以模块和包的形式组织.另外,Python标准库中包含大量模块.本章详细介绍模块和包系统.还将提供有关如何安装第三方模块和分发源代码的信息. ...

  4. OpenCV学习笔记(九) 重映射、仿射变换

    重映射 通过重映射来表达每个像素的位置  : 这里  是目标图像,  是源图像,  是作用于  的映射方法函数.想象一下我们有一个图像  , 我们想满足下面的条件作重映射:,图像会按照  轴方向发生翻 ...

  5. Android TV 开发(4)

    本文来自网易云社区 作者:孙有军 最后我们再来看看好友界面,改界面本地是没有xml的,因此我们直接来看看代码: 这里将使用到数据bean,与数据源的代码也贴出来如下: public class Con ...

  6. 误删除pycharm项目中的文件,如何恢复?

    如果写代码的时候,不小心删除来某个文件夹或者文件,而且删除后回收站也找不到, 可以使用如下方法恢复: 选择 Local History -> Show History : 选中需要reset到的 ...

  7. Redis 配置登录密码

    1. 通过配置文件进行配置 打开 redis.conf,找到 #requirepass foobared 去掉行前的注释,并修改密码为所需的密码,保存文件 重启redis sudo service r ...

  8. SDRAM学习(一)之刷新心得

    本篇博文共有两种刷新方式 SDRAM数据手册给出每隔64ms就要将所有行刷新一遍, 因此每隔64_000_000 ns/2^12=15625ns 就要刷新一次.(因为一个L-Bank的行是12位,所以 ...

  9. redis linux 安装

    安装 1): wget http://download.redis.io/releases/redis-5.0.2.tar.gz 2): tar xzf redis-5.0.2.tar.gz 3):c ...

  10. 微信小程序--问题汇总及详解之picker 增、删

    <block wx:for="{{salesList}}" wx:for-index="index" wx:key="id" wx:f ...