POJ 2771 Guardian of Decency 最大独立集

本文介绍了一个关于最大独立集的问题背景及其解决方案。该问题源于一个保守老师的独特需求,即如何在考虑学生身高、性别、音乐偏好及体育爱好的条件下,找出能够避免形成情侣组合的学生最大数量。文章详细阐述了解决这一问题的算法实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Guardian of Decency
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 4675 Accepted: 1957

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:身高差距大于40(个人认为真心相爱的话身高只是一个符号)
2:性别是一样的
3:音乐喜好不一样
4:运动爱好是一样的
除了第二条,搞不懂这个老师是怎么认为两个人贪恋爱的。。O__O"…
将发生贪恋爱的人配对,则答案为此二分图的最大独立集,因为x,y的集合都是从1~n,左右对称,所以求出最大匹配值之后,还要除以2.
最大独立集=总点个数-最大匹配数。
//1500K	1172MS
#include<stdio.h>
#include<string.h>
#include<math.h>
#define M 507
int link[M],g[M][M];
bool vis[M];
int n;
struct ST
{
    int height;
    char sex[2],music[107],sport[107];
}pupils[M];
bool judge(int x,int y)
{
    if(fabs(pupils[x].height-pupils[y].height)>40||strcmp(pupils[x].sex,pupils[y].sex)==0||strcmp(pupils[x].music,pupils[y].music)!=0||strcmp(pupils[x].sport,pupils[y].sport)==0)
        return false;
    return true;
}
bool find(int i)
{
    for(int j=1;j<=n;j++)
        if(!vis[j]&&g[i][j])
        {
            vis[j]=true;
            if(!link[j]||find(link[j]))
            {
                link[j]=i;
                return true;
            }
        }
    return false;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(link,0,sizeof(link));
        memset(g,0,sizeof(g));
        int count=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d%s%s%s",&pupils[i].height,pupils[i].sex,pupils[i].music,pupils[i].sport);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(judge(i,j))g[i][j]=1;
        for(int i=1;i<=n;i++)
        {
            memset(vis,false,sizeof(vis));
            if(find(i))count++;
        }
        printf("%d\n",n-count/2);
    }
    return 0;
}


CH341A编程器是一款广泛应用的通用编程设备,尤其在电子工程和嵌入式系统开发领域中,它被用来烧录各种类型的微控制器、存储器和其他IC芯片。这款编程器的最新版本为1.3,它的一个显著特点是增加了对25Q256等32M芯片的支持。 25Q256是一种串行EEPROM(电可擦可编程只读存储器)芯片,通常用于存储程序代码、配置数据或其他非易失性信息。32M在这里指的是存储容量,即该芯片可以存储32兆位(Mbit)的数据,换算成字节数就是4MB。这种大容量的存储器在许多嵌入式系统中都有应用,例如汽车电子、工业控制、消费电子设备等。 CH341A编程器的1.3版更新,意味着它可以与更多的芯片型号兼容,特别是针对32M容量的芯片进行了优化,提高了编程效率和稳定性。26系列芯片通常指的是Microchip公司的25系列SPI(串行外围接口)EEPROM产品线,这些芯片广泛应用于各种需要小体积、低功耗和非易失性存储的应用场景。 全功能版的CH341A编程器不仅支持25Q256,还支持其他大容量芯片,这意味着它具有广泛的兼容性,能够满足不同项目的需求。这包括但不限于微控制器、EPROM、EEPROM、闪存、逻辑门电路等多种类型芯片的编程。 使用CH341A编程器进行编程操作时,首先需要将设备通过USB连接到计算机,然后安装相应的驱动程序和编程软件。在本例中,压缩包中的"CH341A_1.30"很可能是编程软件的安装程序。安装后,用户可以通过软件界面选择需要编程的芯片类型,加载待烧录的固件或数据,然后执行编程操作。编程过程中需要注意的是,确保正确设置芯片的电压、时钟频率等参数,以防止损坏芯片。 CH341A编程器1.3版是面向电子爱好者和专业工程师的一款实用工具,其强大的兼容性和易用性使其在众多编程器中脱颖而出。对于需要处理25Q256等32M芯片的项目,或者26系列芯片的编程工作,CH341A编程器是理想的选择。通过持续的软件更新和升级,它保持了与现代电子技术同步,确保用户能方便地对各种芯片进行编程和调试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值