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

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

题目大意:

题意:现在有一个老师想带领他的学生出去郊游,但是他非常担心在郊游的过程中有些学生会发生恋爱关系,而他认为发生恋爱关系的可能性比较小的判断标准有以下四个,如果满足四个条件中的任何一个,即被他认为可能发生恋爱关系的可能性比较小:

            1>两人身高的差距超过40cm;
            2>两人性别相同;
            3>两人所喜欢的音乐风格不同;
            4>两人最喜爱的运动相同;

现在给出n个学生,并给出每个学生的信息(信息为:身高 性别 所喜欢的音乐风格 喜爱的运动),要求求解最大可以带出去郊游的学生数.

思路:
由于两个女生一定不会发生恋爱关系(此处我们不考虑性取向有问题的情况(ORZ)),所以我们可以以该同学的性别为根据来建立二分图。
然后我们在判断两边的同学是否满足上述情况,若满足则连边。然后对于我们建出的这个图在求最大匹配。这样我们就转化成了裸地匈牙利算法。最多可以带的学生数=总学生数-最大匹配数。
注意:char不能用==直接比,这样比出来的只是第一个字符,而非全部,我们这里要用strcmp比较两个字符的大小,这两个字符的字典序如果相同则返回0,如果第一个字符的字典序大返回1,反之,返回-1。
代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 510
using namespace std;
char ch;
bool vis[N];
int t,n,x,ans,gnum,bnum,pre[N],map[N][N];
struct nn
{
    int h;
    ];
    ];
}girl[N],boy[N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
void add_edge()
{
    ;i<=bnum;i++)
     ;j<=gnum;j++)
      )
        map[i][j]=;
}
int find(int x)
{
    ;i<=gnum;i++)
     if(!vis[i]&&map[x][i])
     {
         vis[i]=true;
         ||find(pre[i]))
         {
             pre[i]=x;
             ;
         }
     }
    ;
}
int main()
{
    t=read();
    while(t--)
    {
        ans=;bnum=,gnum=;
        memset(boy,,sizeof(boy));
        memset(girl,,sizeof(girl));
        memset(pre,,sizeof(pre));
        memset(map,,sizeof(map));
        n=read();
        ;i<=n;i++)
        {
            x=read(); scanf("%c",&ch);
            if(ch=='F')
            {
                girl[++gnum].h=x;
                cin>>girl[gnum].fm;
                cin>>girl[gnum].fs;
            }
            else
            {
                boy[++bnum].h=x;
                cin>>boy[bnum].fm;
                cin>>boy[bnum].fs;
            }
        }
        add_edge();
        ;i<=bnum;i++)
        {
            memset(vis,,sizeof(vis));
            if(find(i)) ans++;
        }
        printf("%d\n",n-ans);
    }
    ;
}
 

poj——2771 Guardian of Decency的更多相关文章

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

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

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

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

  3. POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)

    题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...

  4. POJ 2771 Guardian of Decency

    http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40  ②同性 ③喜欢 ...

  5. poj 2771 Guardian of Decency 解题报告

    题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距   ...

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

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

  7. UVA 12083 POJ 2771 Guardian of Decency

    /* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...

  8. poj 2771 Guardian of Decency(最大独立数)

    题意:人与人之间满足4个条件之一即不能成为一对(也就说这4个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...

  9. POJ——T2271 Guardian of Decency

    http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   A ...

随机推荐

  1. Javaweb学习笔记6—EL表达式与JSTL及自定义标签

    今天来讲javaweb的第六阶段学习. EL表达式与JSTL及自定义标签是对上篇文章介绍的JSP的扩展,不能说是很重要的东西,但是也要了解. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps: ...

  2. ldap_modify: No such object (32) matched DN: cn=config

    centos 6.9 部署 kerbors ldap 报错 [root@hadoop data]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ld ...

  3. javaee 第11周

    1.JPQL查询 JPQL全称Java Persistence Query Language 基于首次在EJB2.0中引入的EJB查询语言(EJB QL),Java持久化查询语言(JPQL)是一种可移 ...

  4. Python3简明教程(九)—— 文件处理

    文件是保存在计算机存储设备上的一些信息或数据.你已经知道了一些不同的文件类型,比如你的音乐文件,视频文件,文本文件.Linux 有一个思想是“一切皆文件”,这在实验最后的 lscpu 的实现中得到了体 ...

  5. com组件简单应用

    1.打开VS2010,新建ATL COM 项目,步骤:“文件” -->“新建” -->“项目”,选择“Visual C++” -->“ATL 项目” ,填写“名称” FirstCOM ...

  6. 图片充当li标签列表标志

    默认情况下,浏览器使用一个黑圆圈作为列表标志,可以用图片取代它: ul {list-style: none} ul li{ background-image: url("img/logo_0 ...

  7. 微信小程序---代码构成

    通过开发者工具快速创建了一个demo项目,观察后可以发现这个项目里边生成了不同类型的文件: .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模板文件 .wxss 后缀的 WXSS ...

  8. C++ new delete(二)

    C++基础遗漏:new和delete 我记得当年学习C++基础的时候,老师曾经告诉我们:一般来说new和delete要成对出现,在使用完new申请的内存后要马上释放.我相信持这种说法的人不止我们老师一 ...

  9. kvm安装图终端界面及形界面安装系统

    1.图形界面安装: qemu-img create -f qcow2 /kvm/os/vm-01.qcow2 16G mkdir -p /kvm/iso cd /kvm/iso 上传事先下载好的镜像文 ...

  10. 条款8:别让异常逃离析构函数(prevent exception from leaving destructors)

    NOTE: 1.析构函数绝对不要吐出异常.如果一个被析构函数调用的函数可能抛出异常,析构函数应该扑捉任何异常,然后吞下他们(不传播)或结束程序. 2.如果客户需要对某个操作函数运行期间抛出的异常做出反 ...