POJ3692——Kindergarten(最大二分匹配)

手把手教您如何在飞牛NAS上部署OpenClaw(Clawdbot/Moltbot)智能助手,接入钉钉,0成本使用(万字保姆级教程) 想在飞牛NAS上部署一个24小时待命的AI助手?🤖 本文手把手教您如何在飞牛NAS上部署一个完全免费的OpenClaw智能助手 ✅ 阅读详情

POJ3692——Kindergarten


description:

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.

Input:

The input consists of multiple test cases. Each test case starts with a line containing three integers G, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.
The last test case is followed by a line containing three zeros.

Output:

For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.

Sample Input:

2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0

Sample Output:

Case 1: 3
Case 2: 4

题意:

  • 就是有一群孩子,男孩子之间互相认识,女孩子之间互相认识,并且有部分男孩子和女孩子认识彼此。

  • 现在老师需要选出一个孩子集合,集合中所有的孩子都互相认识。求集合的最大元素个数。

思路:

  • 首先拿到题,我们想到的是肯定是一个匹配题,那么在匹配题中我们要想办法把各种情况转化为最大匹配来算。

  • 首先我们可以通过题目的输入构建一张图,用邻接矩阵表示,这张图就是关系图,如果两个人认识,就记为1。不认识就记为0。

  • 然后我们可以把图转化为补图,那么补图中有边就表示这两个人其实是不认识的,那么我们要做的就是求最小顶点覆盖(找最少的顶点覆盖所有的边),把这些顶点去除补图中就没有边那么就表示在原图中这些人是互相认识的。即可求出答案。


AC代码

//在构图中,我把男孩当做从1到B,女孩当做从B+1到B+1+G。   

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;

    const int maxn = 410; 
    int G,B,M; 
    int map[maxn][maxn];    //邻接矩阵

    int linker[maxn]; 
    bool used[maxn];
    int uN,vN;              

    bool dfs(int u)
    {
        for(int v = 1;v <= vN ;v++)
        {
            if(map[u][v] && !used[v])
            {
                used[v] = true;
                if(linker[v] == -1 || dfs(linker[v]))
                {
                    linker[v] = u;
                    return true; 
                }
            }
        }
        return false;
    }

    int hungary()
    {
        int res = 0;
        memset(linker,-1,sizeof(linker));
        for(int u = 1;u <= uN ;u ++)
        {
            memset(used,false,sizeof(used));
            if(dfs(u)) res ++;
        }
        return res;
    }

    int main()
    {
        int Case = 1;
        while(scanf("%d %d %d",&G,&B,&M) != EOF && !(G == 0 && B == 0 && M == 0))
        {
            memset(map,0,sizeof(map));
            int n = G + B;                //总共G + B 个人 

            //男生之间的联系 
            for(int i = 1; i <= B ;i ++)
            {
                for(int j = 1; j <= B ;j ++)
                {
                    map[i][j] = 1;
                }
            }

            //女孩之间的联系 
            for(int i = B + 1; i <= n ;i ++)
            {
                for(int j = B + 1; j <= n ;j ++)
                {
                    map[i][j] = 1;  
                } 
            }

            //男女之间的联系 
            for(int i = 0; i < M ;i ++)
            {
                int x, y;
                scanf("%d %d",&x,&y);
                map[x + B][y] = 1;
                map[y][x + B] = 1;
            }

            //求补图
            for(int i = 1 ; i <= n ;i ++)
            {
                for(int j = 1;j <= n;j++)
                {
                    if(map[i][j] == 1)
                        map[i][j] = 0;
                    else map[i][j] = 1;     
                }

            } 

            //这个时候有边就表示两个人之间不认识,那么求最小顶点覆盖,除去这些边,那么剩下的人就全部认识了。
            //求最大匹配
            uN = n; vN = n;
            int x = hungary() / 2;
            int ans = n - x;         //最小顶点覆盖求出,用顶点数减去就时答案
            printf("Case %d: %d\n", Case ++, ans);
        }
        return 0;
    }

Python爬虫实战:抓取统计数据并生成年度对比图表详解 国家统计局网站(静态HTML页面Excel文件JSON接口(部分新版API)我们将重点演示从统计公报页面抓取数据,结合解析Excel文件,实现多种数据格式爬取处理。本文从零开始搭建了一个爬取国家统计数据并制作年度对比图表的完整流程。读者可以根据实际需求调整爬取目标,丰富数据分析维度,甚至结合机器学习模型预测未来趋势。欢迎你在评论区留言分享你的爬虫实践,或提出改进建议! 阅读详情

相关推荐

通过两个mark点确定某一个点的位置

read_image (Image0, '0.bmp') binary_threshold (Image0, Region, 'max_separability', 'dark', UsedThreshold) connection (Region, ConnectedRegions) fill_up (ConnectedRegions, RegionFillUp) select_shape_std (RegionFillUp, SelectedRegions, 'max_area', 70) red...

CSDN博客 3891

Kindergarten(POJ-3692)

Problem Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now...

Alex_McAvoy的博客 492

Python制作【大麦网】自动抢票程序

Python 的迅速崛起对整个行业来说都是极其有利的,但“人红是非多”,导致它平添了许许多多的批评,不过依旧挡不住它火爆的发展势头。如果你对Python感兴趣,想要学习pyhton,这里给大家分享一份Python全套学习资料,都是我自己学习时整理的,希望可以帮到你,一起加油!😝有需要的小伙伴,可以点击下方链接免费领取或者V扫描下方二维码免费领取🆓点击这里。

mate1357的博客 2万+

POJ - 3692 Kindergarten(最大独立集/最大匹配)

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all playe

lalalzo的博客 342

LabVIEW内存优化实战:用DVR和队列高效处理大型数组,告别数据副本

本文深入探讨LabVIEW内存优化技术,重点介绍数据值引用(DVR)和单元素队列(SEQs)在高效处理大型数组中的应用。通过对比传统方法与现代引用技术的性能差异,提供减少内存副本、提升程序效率的实战方案,帮助开发者在测试测量、图像处理等数据密集型场景中实现显著性能提升。

weixin_30835649的博客 1063

STM8库函数开发手册(3) //UART1、内部EEPROM、FLASH操作库、IIC(硬、软)

STM8S 微控制器家族的通用同步异步收发器(UART1,UART2 或者UART3)提供了一种灵活的方法与使用工业标准NRZ 异步串行数据格式的外部设备之间进行全双工数据交换。STM8 的UART 提供范围的波特率选择,并且支持多处理器通讯。UART 也支持LIN(局部互联网)协议版本1.3,2.0,和2.1 以及在主模式下的J2602。 UART1 和UAR...

finedayforu的博客 2524

Kindergarten(求二分图最大团转化为求补图的最大独立集(再转化为匈牙利算法求最大匹配))

Link:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5866   Accepted: 2861 Description In a kind

林下的码路 1130

Lammps纳米压痕接触面积—Matlab接触面积计算(两种方法)

Lammps纳米压痕接触面积计算

Rockyoung 5456

POJ 3692 Kindergarten(二分图最大团)

Kindergarten POJ - 3692In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now

w4149 367

ST03N 里看不到 SE38 / SA38?别急,这不是没记录,而是被换了名字

摘要:SAP系统中SE38/SA38事务码在ST03N统计中可能"隐身",因其对话步骤被归集到对应的程序名(如SE38→RSABAPPROGRAM)。ST03N侧重工作负载聚合统计,而STAD提供短期明细记录。正确排查方法是:在ST03N中搜索程序名而非事务码,再通过STAD验证具体使用情况。这一现象在权限整改和审计中易造成误判,建议将程序名纳入常规监控,并区分ST03N(趋势分析)与STAD(事实校验)的不同用途。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 964

S7-1200 PLC PID功能 | 调节PID参数

S7-1200 PLC PID功能 | 调节PID参数

Robot_PLC_HMI_Automation 1万+

POJ2692 Kindergarten 最大团 + 补图二分图

Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7362   Accepted: 3628 Description In a kindergarten, there are a lot of kids. All girls of t

Le Petit Prince 460

LLaMA Factory添加新模型template的实战解析

本文主要介绍了LLaMA Factory添加新模型template的实战解析,希望对使用大语言模型的同学们有所帮助。 文章目录 1. 前言 2. 实战解析 2.1 检查代码 2.2 修改代码

herosunly的博客 19万+

poj3692Kindergarten 二分匹配之最大独立集

//g个girl , b个boy , gril都被彼此认识,boy也彼此认识 //有的girl和boy也彼此认识 //问最多能选出多少人,这些人都彼此认识 //对陌生人建立一个图 //那么其最大独立集就是最多的彼此认识的人 #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int max

ijbuhv的专栏 759

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

poj 3692 Kindergarten(二分匹配,最大独立集)

题目链接 Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6485   Accepted: 3196 Description In a kindergarten, there are a lot of kids. Al

fouzhe的博客 388

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

POJ3692——Kindergarten

Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the

Alex 642

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【二分图最大独立集】POJ 3692:Kindergarten

一、题目内容 POJ 3692 原题地址 二、题意解释 一群男孩女孩,同性之间都相互认识,但是异性之间只有某些人认识彼此。给出相互认识的异性的各自编号。 求组成一个小队,这个小队里的人都相互认识。问这个小队最多能有多少人。 三、代码及注释 #include<stdio.h> #include<iostream> #include<string.h> using namespace std; /* 把相互不了解的人作为边构建二分图,这样题意是选择相互了解的人,那么是选择二

szy_fasheng的博客 217

poj 3692Kindergarten(二分匹配模板)

题意:有n个男生和m个女生,每个男生都认识和每个女生都认识,还有k对关系中的男生和女生都认识,老师想从中选择最大的人数并且这些人都认识 思路:显然这道题可以吧男生看为一个集合,女生为一个集合,然后可以看出,如果把每对认识的连线,然后剩下的都是不认识,那么补图明显是二分图,所以可以有最大团的知识得出 最大团=原图节点数-补图的最大二分匹配数 G的最大团指的是顶点数最多的一个团。 具 体

wuhulala的休息室 1026

POJ 3692 Kindergarten(最大独立集)

POJ 3692 Kindergarten(最大独立集) http://poj.org/problem?id=3692 题意:        已知班级有g个女孩和b个男孩,所有女生之间都相互认识,所有男生之间也相互认识,给出m对关系表示哪个女孩与哪个男孩认识。现在要选择一些学生来组成一个团,使得里面所有人都认识,求此团最大人数。 分析:        任意两个同学之间要么认识,要么不认识

code 962

poj 3692 Kindergarten

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to

---小菜鸟--- 241

POJ 3692 Kindergarten(最大独立集)

POJ 3692 Kindergarten 题目链接 题意:一个班级内,男的都互相认识,女的都互相认识,现在有k对男女互相认识,要求选出最多的人,使得他们两两互相认识 思路:最大独立集,把不认识的连边,就可以求出最大独立集就是两两互相认识的 代码: #include #include #include #include using namespace std;

Remilia's 744

POJ 3692Kindergarten(二分图最大匹配之最小顶点匹配)

题目地址:

scf0920 1065

poj 3692 Kindergarten 二分匹配

题目链接:poj 3692         给定

飞火扑蛾的专栏 467

POJ 3692 Kindergarten 二分图最大独立集

POJ 3692Kindergarten 二分图最大独立集 Description In a kindergarten, there are a lot of kids. All girls of the kids knoweach other and all boys also know each other. In addition to that, some girlsand boy

u013599426的专栏 593

poj -- 3692 Kindergarten (最大完全子图)

<br /> <br />KindergartenTime Limit: 2000MS Memory Limit: 65536K<br />Total Submissions: 2819 Accepted: 1292<br /><br /><br />Description<br /><br />In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know

蓝色污点的专栏 4209

poj3692 Kindergarten

Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7244 Accepted: 3568 DescriptionIn a kindergarten, there are a lot of kids. All girls of the kids know each other and

樱花满地集于我心,楪舞纷飞祈愿相随 308
上一篇: struts2的值栈的初步认识
下一篇: ssh中与前端的json数据交换
WaveBridge
博客等级 码龄10年 8粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值