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. Dtree 添加 checkbox 复选框 可以默认选中

    一:目标 要实现用一个树形结构的展示数据,每个节点(除了根节点)前有一个checkbox,同时,点击父节点,则子节点全选或者全不选,当选中了全部子节点,父节点选中:如下图所示: 同时可以在创建的时候, ...

  2. redhat linux6.5升级openssh

    1.下载最新的openssh包 http://www.openssh.com/portable.html#http 2.升级openssh之前要先打开服务器telnet,通过telnet登录服务器,因 ...

  3. DevOps - 版本控制 - Gogs

    Gogs Gogs官网:https://gogs.io Gogs文档:https://gogs.io/docs Gogs配置文件手册:https://gogs.io/docs/advanced/con ...

  4. vue 判断是否登录,未登录跳转到登录页

    网页一进入判断是否登录,未登录跳转到登录页面 router.js export default new Router({ routes: [ { path: '/', name: 'HelloWorl ...

  5. linux 基本指令 归类

    今天 我们来学习一下 最最基础的linux 指令,在我看来 linux的操作就是 增 删 改 查 这四个字. 1 查询 操作用户 woami 2查询登录用户 who am i 2 pwd //查询当前 ...

  6. Pycharm中F4查看函数的相关小BUG

    我们都知道在Pycharm中我们要快速查看某个函数或者模块的源码,可以在该函数上按F4快捷键,其可以打开源码相关的.py文件,这两天偶然发现起打开的文件不一定是对的. -代码如下: import os ...

  7. volley框架使用

    volley网络请求一个json数据很简单,一句话就搞定了. StringRequest stringRequest=new StringRequest(url, new Listener<St ...

  8. TCP/IP网络编程之基于UDP的服务端/客户端

    理解UDP 在之前学习TCP的过程中,我们还了解了TCP/IP协议栈.在四层TCP/IP模型中,传输层分为TCP和UDP这两种.数据交换过程可以分为通过TCP套接字完成的TCP方式和通过UDP套接字完 ...

  9. 单例模式【python】

    在python中,如需让一个类只能创建一个实例对象,怎么能才能做到呢? 思路:1.通过同一个类创建的不同对象,都让他们指向同一个方向.   2.让个类只能创建唯一的实例对象. 方法:用到 _ _new ...

  10. 剖析微软Hyper-V的最佳部署方式

    剖析微软Hyper-V的最佳部署方式 2014-04-24 10:53 布加迪编译 51CTO.com 字号:T | T 微软Hyper-V有两种不同的版本.既可以安装到Windows Server的 ...