POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)

本文针对一道关于学生配对的问题,通过求解最大独立集来找出最多能有多少人不成为一对的方法。考虑到身高、性别、音乐喜好及运动喜好的限制条件,采用图论中的最大匹配算法来解决该问题。

解题报告

http://blog.youkuaiyun.com/juncoder/article/details/38159017

题目传送门

题意:

看到题目我就笑了,,,

老师认为这样的两个学生不是一对:

身高相差40以上(年龄都不是距离了,身高又算什么)

不同性别(sad,,,就不允许基友存在呀,,,谁的肥皂掉了,,,)

喜欢不一样的歌曲类型(你总不能要求两人整天听小苹果吧,,,,,,你是我的小丫小苹果,,,,,,)

喜欢一样的运动( they are likely to be fans of different teams and that would result in fighting......这是什么理由,喜欢同个不同球队还会打起来

问最多的不在一起的有多少人

思路:

不在一起代表独立于相爱关系的,也就是求最大独立集,集合里面任意两个人都不相爱

最大独立集=结点数-最大匹配

ps不知道是不是写挫了,重写才过,sad。。。

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
    int h;
    char sex;
    char mus[110];
    char spo[110];
}M[510],F[510];
int n,m,f,mmap[550][550],pre[550],vis[550];
int pd(int i,int j)
{
    if( abs(M[i].h - F[j].h) > 40 )
        return 0;
    if( strcmp(M[i].mus,F[j].mus) )
        return 0;
    if( strcmp(M[i].spo,F[j].spo) == 0 )
        return 0;
    return 1;
}
int dfs(int x)
{
    for(int i=m+1;i<=m+f;i++){
        if(!vis[i]&&mmap[x][i]){
            vis[i]=1;
            if(pre[i]==-1||dfs(pre[i])){
                pre[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int i,j,t,h;
    char str[100];
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        m=f=1;
        memset(mmap,0,sizeof(mmap));
        memset(pre,-1,sizeof(pre));
        memset(M,0,sizeof(M));
        memset(F,0,sizeof(F));
        for(i=1;i<=n;i++){
            scanf("%d%s",&h,str);
            if(str[0]=='M'){
                scanf("%s%s",M[m].mus,M[m].spo);
                M[m].h=h;
                M[m++].sex='M';
            }
            else {
                scanf("%s%s",F[f].mus,F[f].spo);
                F[f].h=h;
                F[f++].sex='F';
            }
        }
        for(i=1;i<=m;i++){
            for(j=1;j<=f;j++){
                if(pd(i,j))
                mmap[i][m+j]=1;
            }
        }
        int ans=0;
        for(i=1;i<=m;i++){
            memset(vis,0,sizeof(vis));
            ans+=dfs(i);
        }
        printf("%d\n",n-ans);
    }
}

Guardian of Decency
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 4876 Accepted: 2056

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


<think>我们有一个链接命令的片段,需要解释每个部分的含义。这个命令片段看起来是用于链接器的选项,通常在编译(特别是使用gcc或ld)时使用。以下是逐部分的解释: 1. `-L/home/wangrui66/wangrui_poj/bcm/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be900v2/usr/lib`: - `-L`选项用于指定链接器搜索库文件的目录。这里指定了一个具体的路径,链接器会在这个目录下查找后续`-l`选项指定的库。 2. `-lz`: - `-l`选项用于链接指定的库。`-lz`表示链接名为`libz.so`(或`libz.a`)的库,即zlib压缩库。 3. `-lbz2`: - 同理,链接名为`libbz2.so`(或`libbz2.a`)的库,即bzip2压缩库。 4. `-lpng12`: - 链接名为`libpng12.so`(或`libpng12.a`)的库,即PNG图像处理库的1.2版本。 5. `-pthread` 和 `-lpthread`: - `-pthread`是一个多线程相关的编译和链接选项,它确保在编译和链接时正确处理多线程(例如设置预定义的宏,并链接线程库)。在链接阶段,它通常等同于`-lpthread`,即链接名为`libpthread.so`的线程库(POSIX线程库)。 - 这里同时出现了`-pthread`和`-lpthread`,可能是为了确保兼容性,但通常只需要一个(现代编译器通常推荐使用`-pthread`,因为它同时处理编译和链接)。 6. `-no-undefined`: - 这是一个链接器选项(ld的选项),指示链接器在生成共享库时,不允许出现未定义的符号。如果存在未定义的符号,链接器会报错。这个选项通常用于创建共享库(.so文件)时使用。 7. `-export-symbols`: - 这个选项后面通常会跟一个文件,用于指定要从共享库中导出的符号(函数或变量)。但是在这个命令片段中,它后面没有直接给出文件,可能是省略了或者位于后续的参数中。这个选项用于控制共享库的符号可见性。 注意:这个命令片段看起来是用于链接一个共享库(因为使用了`-no-undefined`和`-export-symbols`),并且指定了多个依赖库。 总结:整个命令的作用是链接一个程序或共享库,它指定了库的搜索路径(通过`-L`),并链接了zlib、bzip2、libpng12以及POSIX线程库,同时要求链接时不允许未定义符号,并且指定了导出符号(但这里没有给出符号文件,可能是命令不完整)。 §§相关问题§§1. 在链接器命令中,-L和-l选项的作用是什么?2. 为什么在链接线程程序时需要使用-pthread选项?3. 什么是未定义符号错误,如何解决?4. 如何控制共享库中哪些符号被导出?5. 在交叉编译环境中,如何指定目标平台的库路径? </think>这个命令是 **链接器(ld)的选项组合**,用于在编译程序时指定库的搜索路径和依赖库。以下是逐项解析: ```bash -L/home/wangrui66/wangrui_poj/bcm/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be900v2/usr/lib ``` - **`-L`**:指定**库文件的搜索路径** - **路径含义**:指向 OpenWrt 交叉编译环境的 ARM 架构库目录(uclibc 标准库) ```bash -lz -lbz2 -lpng12 ``` - **`-l`**:链接指定的库文件 - **`-lz`**:链接 zlib 压缩库 (`libz.so`/`libz.a`) - **`-lbz2`**:链接 bzip2 压缩库 (`libbz2.so`/`libbz2.a`) - **`-lpng12`**:链接 PNG 1.2 图像库 (`libpng12.so`/`libpng12.a`) ```bash -pthread -lpthread ``` - **`-pthread`**:启用 POSIX 线程支持(编译器标志) - **`-lpthread`**:链接 pthread 线程库 (`libpthread.so`) ```bash -no-undefined ``` - 强制要求**所有符号必须被定义**(主要用于创建共享库时禁止未解析符号) ```bash -export-symbols ``` - 指定**导出的符号列表**(通常后接符号文件,但此处未给出文件名,可能不完整) ### 完整作用: 此命令组合主要用于 **ARM 交叉编译环境下的共享库链接**,实现: 1. 在指定目录查找依赖库 2. 链接压缩库(zlib/bzip2)和图像库(libpng) 3. 启用多线程支持 4. 确保符号完整性 5. 控制符号导出范围
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值