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 ≤ MG × 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

Source

2008 Asia Hefei Regional Contest Online by USTC

题意就是让你找出最多的人,他们之间是相互认识的,条件告诉我们男孩和男孩是相互认识的,女孩也是,而且部分男孩女孩认识,那么我们就可以以男孩为一个集合,女孩为一个集合,然后二分匹配,如果某个男孩和某个女孩不认识,我们就连一条边,进行最大匹配。然后求最大独立集,由于建边的缘故,最大独立集里的点其实是相互认识的。
#include<stdio.h>
#include<string.h>

const int maxn=205;
bool each[maxn][maxn];
struct node
{
	int to;
	int next;
}edge[maxn*maxn];
int head[maxn];
int mark[maxn];
bool used[maxn];
int tot;
int N;
void addedge(int from,int to)
{
	edge[tot].to=to;
	edge[tot].next=head[from];
	head[from]=tot++;
}

bool dfs(int x)
{
	for(int i=head[x];i!=-1;i=edge[i].next)
	{
		if(!used[edge[i].to])
		{
			used[edge[i].to]=1;
			if(mark[edge[i].to]==-1 || dfs(mark[edge[i].to]))
			{
				mark[edge[i].to]=x;
				return true;
			}
		}
	}
	return false;
}

int hungary()
{
	int ans=0;
	memset(mark,-1,sizeof(mark));
	for(int i=1;i<=N;i++)
	{
		memset(used,0,sizeof(used));
		if(dfs(i))
		  ans++;
	}
	return ans;
}

int main()
{
	int G,B,M,icase=1;
	while(~scanf("%d%d%d",&G,&B,&M))
	{
		if(!G && !B && !M)
		  break; 
		memset(each,0,sizeof(each));//数组值为0代表相互不认识 
		memset(head,-1,sizeof(head));
		tot=0;
		N=G;
		int x,y;
		for(int i=1;i<=M;i++)
		{
			scanf("%d%d",&x,&y);
			each[x][y]=1;//相互认识 
		}
		for(int i=1;i<=G;i++)
		  for(int j=1;j<=B;j++)
		  {
  			if(!each[i][j])//相互不认识的连边 
 			 	addedge(i,j);
  		  }
       printf("Case %d: %d\n",icase++,G+B-hungary());
	}
	return 0;
}



内容概要:本文介绍了一项创新性未发表的研究,即利用多元宇宙优化算法(Multiverse Optimizer, MVO)对分时电价下的需求响应与综合能源系统调度问题进行建模与求解,旨在实现能源系统的经济性、高效性与可持续性运行。该研究构建了包含多种能源设备(如光伏、风机、燃气轮机、储能系统等)及可调节负荷的综合能源系统模型,充分考虑了用户侧的需求响应行为在分时电价机制下的响应特性,通过MVO算法对系统运行成本、能源利用率、碳排放等多目标进行协同优化,实现了日前调度计划的智能决策。研究还提供了完整的MATLAB代码实现,便于研究人员复现实验、验证算法性能,并为进一步研究提供可靠的仿真基础。; 适合人群:具备一定电力系统、优化算法及MATLAB编程基础的科研人员、研究生以及从事能源互联网、综合能源系统规划与运行的技术工程师。; 使用场景及目标:① 学习并掌握多元宇宙优化算法在复杂能源系统调度中的具体应用方法;② 研究分时电价机制如何通过需求响应引导用户参与电网互动,实现削峰填;③ 实现综合能源系统(IES)中冷、热、电、气等多种能源的协同优化调度,以降低运行成本、提高新能源消纳能力和系统可靠性;④ 为相关领域的学术研究提供可复现的代码实例和仿真平台。; 阅读建议:此资源以MATLAB代码为核心载体,深入剖析了算法应用与系统建模的全过程。建议读者在学习时,不仅应关注代码的实现细节,更要理解其背后的数学模型、优化目标设定和约束条件的物理意义。建议结合文档中的模型描述,逐步调试代码,观察不同参数和场景下的优化结果,从而深刻掌握综合能源系统优化调度的设计思想与关键技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值