The Accomodation of Students HDU - 2444(最大二分匹配+染色法判断二分图)

探索热阻测试仪在半导体器件热管理中的应用与前景 T3Ster是MicReD研发的热测试仪,运用JEDEC稳态实时测试方法,专业测试分离或集成的双极型晶体管、MOS晶体管、常见的三极管、LED封装和半导体闸流管等器件的热特性。利用瞬态温升技术,可测得器件稳态热阻和温升,不但可以测得半导体器件稳态热阻和温升,而且可以直接测量各部分对于温升的贡献,计算芯片热流路径上的纵向热阻构成,对器件热可靠性设计、散热问题解决、产品性能提升和长期可靠性至关重要。关键词:T3ster,Micred,功率循环,结温测试,热阻测试,结温热阻测试,半导体热特性测试; 阅读详情

There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.

Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.

Calculate the maximum number of pairs that can be arranged into these double rooms.

Input
For each data set:
The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs.

Proceed to the end of file.

Output
If these students cannot be divided into two groups, print "No". Otherwise, print the maximum number of pairs that can be arranged in those rooms.
Sample Input
4 4
1 2
1 3
1 4
2 3
6 5
1 2
1 3
1 4
2 5
3 6
Sample Output
No
3

思路:首先利用染色法判断一下这个图是否是一个二分图,然后找最大二分匹配,找的过程中为了简单化,把两边均看成有n个点,即正反都记录,求出最终结果,然后用找到的匹配数除以2 就是正确答案

其中染色法:

怎么判定一个图是否为二分图
从其中一个定点开始,将跟它邻接的点染成与其不同的颜色,最后如果邻接的点有相同颜色,则说明不是二分图,每次用bfs遍历即可。

染色法模板:

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

const int N = 999;  
int col[N], Map[N][N];  

//0为白色,1为黑色   
bool BFS(int s, int n) 
{  
    queue<int> p;  
    p.push(s);  
    col[s] = 1;  //将搜索起始点涂成黑色
    while(!p.empty()) 
    {  
        int from = p.front();  
        p.pop();  
        for(int i = 1; i <= n; i++) 
        {  
            if(Map[from][i] && col[i] == -1) //如果从from到i的边存在(为邻接点) && i点未着色
            {  
                p.push(i);          //将i点加入队列
                col[i] = !col[from];//将i点染成不同的颜色   
            }  
            if(Map[from][i] && col[from] == col[i])//如果从from到i的边存在(为邻接点) && i点和from点这一对邻接点颜色相同,则不是二分图   
                return false;  
        }  
    }  
    return true;  //搜索完s点和所有点的关系,并将邻接点着色,且邻接点未发现相同色则返回true     
}  

int main() 
{  
    int n, m, a, b;  
    memset(col, -1, sizeof(col));  
    cin >> n >> m;  //n 为有多少点,m为有多少边  
    for(int i = 0; i < m; i++) 
    {  
        cin >> a >> b;  
        Map[a][b] = Map[b][a] = 1;   
    }  
    bool flag = false;  
    for(i = 1; i <= n; i++)  //遍历并搜索各个连通分支
    {    
        if(col[i] == -1 && !BFS(i, n)) //每次找没有着色的点进行判断,如果从它开始BFS发现相同色邻接点则不是二分图
        {   
            flag = true;  
            break;    
        }  
    }
    if(flag)  
        cout << "NO" <<endl;      
    else  
        cout << "YES" <<endl;  
    return 0;  
}  

题解code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int mp[1000][1000];//记录关系的数组 
int match[1000];//最大二分匹配数组 
int vis[1000];//标记数组 
int color[1000];//染色数组
int n,m;
int Judge();//判断是否是二分图;
int bfs(int u);//判断二分图的广搜函数
int findMax();//找最大二分匹配
int dfs(int u);//找最大二分匹配的深搜函数 
int main(){
	while(cin >> n >> m){
		int i;
		memset(mp,0,sizeof(mp));
		for(i = 0; i < m; i++){
			int u,v;
			cin >> u >> v;
			mp[u][v] = mp[v][u] = 1;
		}
		int flag = Judge();
		if(!flag){
			cout << "No" << endl;
			continue;
		}
		cout << findMax()/2 << endl;
	}
	return 0;
}
int Judge(){
	int i;
    memset(color,0,sizeof(color));
	for(i = 1; i <= n; i++){
		if(color[i] == 0 && !bfs(i)){
			return 0;
		}
	}
	return 1;
}
int bfs(int u){
	queue<int>q;
	q.push(u);
	color[u] = 1;//给起点上色
	while(!q.empty()){
		int f = q.front();
		q.pop();
		int i;
		for(i = 1; i <= n; i++){
			if(mp[f][i]){
				if(color[i] == color[f])
				  return 0;
				else if(color[i] == 0){
					color[i] = -color[f];
					q.push(i);
				}
			}
		}
	}
	return 1; 
}
int findMax(){
	int i;
	int cnt = 0;
	memset(match,0,sizeof(match));
	for(i = 1; i <= n; i++){
		memset(vis,0,sizeof(vis));
		if(dfs(i))
		  cnt++;
	}
	return cnt;
}
int dfs(int u){
	int i;
	for(i = 1; i <= n; i++){
		if(mp[u][i] && !vis[i]){
			vis[i] = 1;
			if(!match[i] || dfs(match[i])){
				match[i] = u;
				return 1;
			}
		}
	}
	return 0;
}


Xilinx FPGA平台GTX简易使用教程(四)GTX IP核配置教程 干货来了,GTX IP核配置,搬砖全靠它~~ 阅读详情

相关推荐

ModusToolbox 实战避坑指南|从环境配置到项目构建

本文是一份详尽的ModusToolbox实战避坑指南,手把手教你从环境配置到项目构建。重点解决了Windows系统下的安装、关键环境变量CY_TOOLS_PATHS的设置、PowerShell执行策略调整以及利用URL Modifier工具优化GitHub资源下载等核心难题,旨在帮助开发者,特别是英飞凌(Infineon)芯片用户,顺利搭建开发环境并成功运行第一个Hello World程序。

t1u2v的博客 590

HDU2444 The Accomodation of Students(二分匹配 匈牙利算法)

Problem Description There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A a

左眼皮跳跳 729

Stata实战:用双向固定效应模型分析房价,从数据清洗到结果解读(附完整代码)

本文详细介绍了如何使用Stata实现房价数据的双向固定效应模型分析,从数据清洗到结果解读的全流程。通过具体代码示例,帮助读者掌握面板模型的应用技巧,特别适合经济学和金融学研究者进行房价影响因素分析。

weixin_31528001的博客 276

The Accomodation of Students(HDU-2444)(二分图判定与最大匹配)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7104

殇星痕的博客 491

Win11家庭版彻底关闭Hyper-V的3种方法(实测有效)

本文详细介绍了Win11家庭版彻底关闭Hyper-V的3种实测有效方法,解决与VMware的兼容性问题。包括命令行禁用虚拟化功能、微软官方工具DG_Readiness深度清理以及组策略与功能组件联用方案,帮助用户高效禁用Hyper-V并优化系统性能。

weixin_33728268的博客 2657

高通camera:PDAF的配置与测试

确认相关log日志都已经打开了之后,判断是在3A算法中没有应用到PDAF,可能是之前在调试AF效果的时候关闭了PDAF,打开效果文件对应的文件夹,在\kamorta_lce_S5K3P9\Scenario.Default\XML\STATS。在log中搜索af_pdaf_proc_pd_single,这个函数是pdaf算法中的,源码被封装了,这里看不到,因此只能通过log打印出来的参数来分析pd是否正确,主要参数有pd ,defocus,confidence。PDAF的配置与测试。

arvin_xiong的博客 2484

The Accomodation of Students(HDU-2444 )

Problem Description There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A ...

Alex_McAvoy的博客 693

蓝桥杯第七届省赛试题--“模拟风扇控制系统”

题目要求 功能简述 “模拟风扇控制系统”能够模拟电风扇工作,通过按键控制风扇的转动速度和定时时间,数码管实时显示风扇的工作模式,动态倒计时显示剩余的定时时间,系统主要由数码管显示、单片机最小系统、按键输入和电机控制保护电路组成,系统框图如图 1 所示: 单总线驱动程序、CT107D 单片机考试平台电路原理图以及本题所涉及到的芯片数据手册,可参考计算机上的电子文档。程序流程图及相关工程文件请以考生...

qq_43280087的博客 2658

The Accomodation of Students(二分图判断+匈牙利)

The Accomodation of Students Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2444 Description There are a group of students. Som

AI蜗牛之家 1706

基于 InceptionNeXt 模块增强的 YOLOv8 模型:针对多尺度目标检测的改进与实现

modules.py。

know_F0727的博客 203

硬件测试有哪些?

硬件单元测试(UT)是验证电路功能与可靠性的关键环节,主要分为电源测试和信号测试两大模块。电源测试需验证输入电压范围、高低压极限、短路保护等功能,确保供电稳定性;信号测试则聚焦时钟、总线、存储等接口的时序与完整性。测试要求统一标准、可追溯数据、问题闭环处理,通过开发与测试协同确保质量。规范的单元测试能有效降低后期集成风险,提升产品可靠性,其核心始终是在最小单元上确保稳健性,为系统级可靠性奠定基础。

硬核科技 244

HDU-2444 The Accomodation of Students(二分图匹配+判断)

The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8233    Accepted Submission(s): 3630Problem DescriptionThere are a g...

Amove 283

探索如何利用CST和ADS进行DDR的SIPI联合仿真

本文系统介绍了CST和ADS两款工具进行DDR信号完整性/电源完整性(SI/PI)联合仿真的方法。CST采用工作室协同方式,通过PCB布局导入、材料设置、模型分配等步骤,重点分析了电源阻抗优化和信号波形质量。ADS则利用SIPro、PIPro等专用工具,突出系统级验证和自动化优化功能。两者各有优势:CST擅长3D结构精确建模,ADS更适于快速系统验证。文章建议可根据项目需求混合使用两种工具,并提供了模型简化、频带选择等实用技巧。通过对比分析,为工程师选择仿真工具提供了决策参考。

一只豌豆象的博客 1149

HDU 2444 The Accomodation of Students 染色法 +最大匹配

一、内容 There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each ...

Tizzi的博客 960

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

HDU - 2444——The Accomodation of Students(判断二分图,二分图最大匹配)

题意: 题意: 有n个人,m对人相互认识; 问能否分成两个组,组内任意两个人之间不认识; 若不能,则输出No; 若能,则相互认识的两个人一间房,求最多需要几间房; 给出一些学生的认识情况,比如A和B认识,B和C认识,但是A和C不一定认识。现在问能否将这些学生分成两个组,并且每组中的学生互相不认识,如果能分,求出最大能匹配的学生对数。 题目 There are a group of students...

zeng_jun_yv的博客 475

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

二分图判定+最大匹配+例题HDU2444 The Accomodation of Students

注:本文参考博客链接:二分图大合集 二分图定义: 二分图也称二部图,是图论里的一种特殊模型,也是一种特殊的网络流。其最大的特点在于,可以将图里的顶点分为两个集合,且集合内的点没有直接关联。 二分图判定: 如果某个图为二分图,那么它至少有两个顶点,且其所有回路的长度均为偶数(或者回路中结点个数为偶数),任何无回路的的图均是二分图。 判断二分图的方法: 判断二分图方法:用染色法,把图中的点染成黑色和白色。 首先取一个点染成白色,然后将其相邻的点染成黑色,如果发现有相邻且同色的点,那么就退出,可知这个图并非二分图

the best 的博客 906

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU 2444 The Accomodation of Students (二分图最大匹配+二分图染色)

【题目链接】:click here~~  【题目大意】: 给出N个人和M对关系,表示a和b认识,把N个人分成两组,同组间任意俩人互不认识,若不能分成两组输出No,否则输出两组间俩人互相认识的对数 【解题思路】:   先判断能否构成二分图,判断二分图用交叉染色法:从某个未染色的点出发把此点染成白色,该点周围的点染成黑色,黑色周围的又染成白色,若走到某个点已经染色,并且它相邻点的颜色与它一样

herongwei 的 BLOG 1717

hdu 2444 The Accomodation of Students (二分染色)

http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Problem Description There are a group of students. Some of them may know each other, while others don't. For exam

大太阳 839

HDU 2444 The Accomodation of Students 二分图判断+最大匹配

There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other....

xiongshuxian2019的博客 210

HDU2444 The Accomodation of Students(染色法判断二分图)

The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7360    Accepted Submission(s): 3284 Problem Description T

zezzezzez的博客 238

HDU2444 The Accomodation of Students(二分图判断+匈牙利匹配)

题目链接 Problem Description There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other. Now you are given all pairs of

WTMDNM_的博客 174

HDU 2444 The Accomodation of Students 二分图判定 二分匹配

题意:有n个人,给出其中相互认识的几对,求出是否能够分出两组人,其中每组中任意两个人互不认识,然后将两组中认识的两个人分到同一个房间里,若能分出这样的两组,求出分到的房间的最多个数 思路:即判定给定图是否是二分图,若是二分图则求最大匹配。判定二分图用bfs染色法,对于每个点,与其连接的点染上与其相反的颜色,若某点连接的点与其颜色相同,说明图不是二分图 #include<iostream&gt...

qq_42397248的博客 221

The Accomodation of Students HDU - 2444(染色法判断是否为二分图&&二分图匹配)

There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other....

starlet_kiss的博客 191

HDU - 2444 The Accomodation of Students(二分图判断+二分图最大匹配)

题目链接:点击查看 题目大意:给出n个学生,他们之间有m个认识关系,但认识关系不具有传递性,比如A认识B,B认识C,A不一定认识C,现在给出认识关系,先判断是否能够将所有学生分为两个集合A和B中去,集合A中的所有学生都互不认识,集合B中的学生也互不认识,集合A中的学生可以和集合B中的学生认识,若能分成两个集合,问最多有几个认识的关系 题目分析:看完题后再看了一眼样例,就是个模板题,二分图的判断...

Falcon的博客 449

The Accomodation of Students HDU - 2444(二分图判断+匈牙利)

染色法判断二分图:对一个点染色为1,对其全部有连线的邻接点染色为与其不用的颜色0,再对所有邻接点的邻接点染色为1,以此类推,当发现一个点i,其邻接点中有一个点的颜色与点i相同则非二分图 #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<...

仰望蓝天的博客 172

B - The Accomodation of Students HDU - 2444

题目链接 解题思路: 题目先问能不能成为二分图,那么直接用染色法判断即可 之后标准二分图匹配 AC代码: #include <iostream> #include <algorithm> #include <cstring> #include <stdio.h> #include <cmath> using namespace std; const int maxn = 210; const int maxm = 41000; int n, m

trouble_的博客 200
上一篇: 最大报销额 HDU 1864(01背包)
下一篇: Courses HDU - 1083(最大二分图匹配)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值