2771 Guardian of Decency //MaxMatch

本文介绍了一个基于最大独立集算法的问题解决方法,旨在帮助一位保守的高中教师筛选出最合适的学生参加户外活动,确保不会有任何学生发展成情侣关系。通过构建二分图并运用匈牙利算法求解最大匹配数,进而得到最大独立集。

 

 

Guardian of Decency
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 3126 Accepted: 1308

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

 

 

         将所有可以发生恋爱关系的男女进行配对,即将男同学和女同学做为两个顶点集合,如果某一对男女同学能发生恋爱关系,就将二者连接,从而建立二分图,那么可以带的出去的人数应该等于这个二分图的最大独立集.
         最大独立集:最大的一个集合,其中的每两点之间都不存在边.
         最大独立集=顶点数-最大匹配数.

 

 

#include<iostream>

#include<string.h>

#include<cstdlib>

#include<cmath>

#include<cstdio>

#include<algorithm>

using namespace std;

int usedif[501];

//usedif[i]记录Y顶点子集中编号为i的顶点是否使用,注意Y子集中的最多顶点数为(7-1)*12+12=84

int link[501];//link[i]记录与Y顶点子集中编号为i的顶点相连的X顶点子集中x的编号

int mat[501][501];//mat[i][j]表示顶点i与j之间是否有边

int bn,gn;//gx为X顶点子集中的顶点数目,gy为Y顶点子集中的顶点数目

struct People                                                          //存储学生信息

{

    int h;

    char sex;

    char mu[105];

    char sp[105];

} boy[505],girl[505];

bool can(int t)                                                     //判断Y集合中的顶点是否能与X集合中的顶点t匹配

{

    int i;

    for(i=0;i<gn;i++)

    {

       if(!usedif[i]&&mat[t][i])

       {

            usedif[i]=true;

            if(link[i]==-1||can(link[i]))

            {

                link[i]=t;

                return true;

            }

       }

    }

    return false;

}

int MaxMatch()                                                      //求解最大匹配数

{

    int i,num=0;

    memset(link,-1,sizeof(link));

    for(i=0;i<bn;i++)

    {

        memset(usedif,0,sizeof(usedif));

        if(can(i))

           num++;

    }

    return num;

}

int main()

{

    int i,j,t,n,ans;

    People p;

    scanf("%d",&t);

    while(t--)

    {

         scanf("%d",&n);

         bn=gn=ans=0;

         for(i=0;i<n;i++)

         {

             scanf("%d %c %s %s",&p.h,&p.sex,p.mu,p.sp);

             if(p.sex=='M')

                  boy[bn++]=p;

             else if(p.sex=='F')

                  girl[gn++]=p;

         }

         memset(mat,0,sizeof(mat));

         for(i=0;i<bn;i++)

           for(j=0;j<gn;j++)

              if(abs(boy[i].h-girl[j].h)<=40&&strcmp(boy[i].mu,girl[j].mu)==0&&strcmp(boy[i].sp,girl[j].sp)!=0)

                 mat[i][j]=true;

         ans=n-MaxMatch();

         printf("%d/n",ans);

    }

    return 0;

}

 

 

本课题设计了一种利用Matlab平台开发的植物叶片健康状态识别方案,重点融合了色彩与纹理双重特征以实现对叶片病害的自动化判别。该系统构建了直观的图形操作界面,便于用户提交叶片影像并快速获得分析结论。Matlab作为具备高效数值计算与数据处理能力的工具,在图像分析与模式分类领域应用广泛,本项目正是借助其功能解决农业病害监测的实际问题。 在色彩特征分析方面,叶片影像的颜色分布常与其生理状态密切相关。通常,健康的叶片呈现绿色,而出现黄化、褐变等异常色彩往往指示病害或虫害的发生。Matlab提供了一系列图像处理函数,例如可通过色彩空间转换与直方图统计来量化颜色属性。通过计算各颜色通道的统计参数(如均值、标准差及主成分等),能够提取具有判别力的色彩特征,从而为不同病害类别的区分提供依据。 纹理特征则用于描述叶片表面的微观结构与形态变化,如病斑、皱缩或裂纹等。Matlab中的灰度共生矩阵计算函数可用于提取对比度、均匀性、相关性等纹理指标。此外,局部二值模式与Gabor滤波等方法也能从多尺度刻画纹理细节,进一步增强病害识别的鲁棒性。 系统的人机交互界面基于Matlab的图形用户界面开发环境实现。用户可通过该界面上传待检图像,系统将自动执行图像预处理、特征抽取与分类判断。采用的分类模型包括支持向量机、决策树等机器学习方法,通过对已标注样本的训练,模型能够依据新图像的特征向量预测其所属的病害类别。 此类课题设计有助于深化对Matlab编程、图像处理技术与模式识别原理的理解。通过完整实现从特征提取到分类决策的流程,学生能够将理论知识与实际应用相结合,提升解决复杂工程问题的能力。总体而言,该叶片病害检测系统涵盖了图像分析、特征融合、分类算法及界面开发等多个技术环节,为学习与掌握基于Matlab的智能检测技术提供了综合性实践案例。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
<think>我们之前将脚本复制到/tmp目录并尝试执行,但系统返回"not found"错误。这通常与以下原因有关: 1. 脚本解释器路径错误(Shebang问题) 2. 脚本本身的编码或格式问题(如Windows换行符) 3. 动态链接库缺失(但本例是脚本,可能性低) 4. /tmp目录的特殊限制(如noexec挂载选项) 具体分析步骤: </think>### 脚本 "not found" 错误深度分析及解决方案 您在执行 `/tmp/monitor_guardian.sh` 时遇到 **`not found`** 错误,这通常与以下关键问题相关: #### 🔍 根本原因诊断 1. **Shebang 解释器路径错误** - 脚本首行 `#!/path/to/interpreter` 指定的解释器不存在 - 常见错误:`#!/bin/sh` 指向不存在的路径(如 BusyBox 系统使用 `/bin/ash`) 2. **文件编码/格式问题** - Windows 换行符(`\r\n`)导致 Linux 无法识别脚本 - UTF-8 BOM 头破坏 Shebang 解析 3. **动态链接器缺失** - 编译型脚本(如 Python)依赖的库路径错误 - 32/64 位兼容性问题 4. **/tmp 目录限制** - 系统启用 `noexec` 挂载选项: ```bash mount | grep /tmp # 查看挂载参数 ``` --- #### ️ 修复步骤 **步骤1:验证脚本完整性** ```bash # 检查Shebang行 head -n1 /tmp/monitor_guardian.sh # 手动指定解释器执行(绕过Shebang) /bin/sh /tmp/monitor_guardian.sh # 尝试常见解释器 /bin/bash /tmp/monitor_guardian.sh /usr/bin/env python /tmp/monitor_guardian.sh ``` **步骤2:修复文件格式** ```bash # 移除Windows换行符 sudo apt-get install dos2unix # 安装工具 dos2unix /tmp/monitor_guardian.sh # 或使用sed sed -i 's/\r$//' /tmp/monitor_guardian.sh ``` **步骤3:绕过 /tmp 限制** ```bash # 创建可执行目录 mkdir ~/scripts cp /tmp/monitor_guardian.sh ~/scripts/ chmod +x ~/scripts/monitor_guardian.sh ~/scripts/monitor_guardian.sh & ``` **步骤4:检查脚本依赖** ```bash # 查看动态链接(针对二进制脚本) ldd /tmp/monitor_guardian.sh 2>/dev/null # 修复库路径 export LD_LIBRARY_PATH=/correct/lib/path:$LD_LIBRARY_PATH ``` --- #### ️ 高级故障排除 - **文件类型验证**: ```bash file /tmp/monitor_guardian.sh # 确认是脚本还是二进制 ``` - **执行权限陷阱**: ```bash # 即使有x权限,若目录无x权限仍会失败 ls -ld /tmp # 目录需有 --x--x--x 权限 ``` - **SELinux/AppArmor 拦截**: ```bash audit2allow -a # 查看安全拦截日志 setenforce 0 # 临时禁用SELinux(仅测试) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值