ZOJ 1197 Sorting Slides (二分图最大匹配:求关键边)

本文介绍了一种解决幻灯片排序问题的算法,通过构建最大二分图匹配模型,确定每张幻灯片在其堆叠状态下的确切位置。文章详细阐述了如何通过删除边来判断关键边,从而确定幻灯片与其位置的唯一对应关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sorting Slides

Time Limit: 1000MS         Memory Limit: 10000K
Total Submissions: 5070         Accepted: 1983
Description

Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minimalist, he wants to do this with the minimum amount of work possible. 

The situation is like this. The slides all have numbers written on them according to their order in the talk. Since the slides lie on each other and are transparent, one cannot see on which slide each number is written. 


Well, one cannot see on which slide a number is written, but one may deduce which numbers are written on which slides. If we label the slides which characters A, B, C, ... as in the figure above, it is obvious that D has number 3, B has number 1, C number 2 and A number 4. 

Your task, should you choose to accept it, is to write a program that automates this process.

Input

The input consists of several heap descriptions. Each heap descriptions starts with a line containing a single integer n, the number of slides in the heap. The following n lines contain four integers xmin, xmax, ymin and ymax, each, the bounding coordinates of the slides. The slides will be labeled as A, B, C, ... in the order of the input. 

This is followed by n lines containing two integers each, the x- and y-coordinates of the n numbers printed on the slides. The first coordinate pair will be for number 1, the next pair for 2, etc. No number will lie on a slide boundary. 

The input is terminated by a heap description starting with n = 0, which should not be processed. 

Output

For each heap description in the input first output its number. Then print a series of all the slides whose numbers can be uniquely determined from the input. Order the pairs by their letter identifier. 

If no matchings can be determined from the input, just print the word none on a line by itself. 

Output a blank line after each test case. 

Sample Input

4
6 22 10 20
4 18 6 16
8 20 2 18
10 24 4 8
9 15
19 17
11 7
21 11
2
0 2 0 2
0 2 0 2
1 1
1 1
0
Sample Output

Heap 1
(A,4) (B,1) (C,2) (D,3)
 
Heap 2

none

题意描述:给你n张幻灯片的左上角坐标和右下角坐标,然后给出A,B,C.....等幻灯片的一个坐标,判断能否将所有幻灯片和其位置对应,如果能对应输出对应的顺序,不能则输出none。

分析:最大二分图匹配问题。关键边:是除去一条边之后图相比之前来说不连通了(其实就是最大匹配数少了)我们建图之后找出所有的关键边,再输出答案。找关键边的方法是,先删除一条边,在此情况下,最大匹配边没有少的话,他就不是关键边,同理如果少了,他就是关键边。

代码如下:

#include<stdio.h>
#include<string.h>
int a[510][510];//储存边的数组 
int match[510];//匹配关系数组 
int book[510];//标记数组 
int n;
int xmin[510],xmax[510],ymin[510],ymax[510],x[510],y[510];
int dfs(int u)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(book[i]==0&&a[u][i]==1)//如果i未被访问且u与i匹配 
		{
			book[i]=1;//标记点i已被访问
			if(match[i]==0||dfs(match[i]))//如果点i未被配对或者找到了新的配对
			{
				match[i]=u;//更新配对关系
				return 1;
			}
		}
	}
	return 0;
}
int connect()
{
	int i;
	memset(match,0,sizeof(match));
	for(i=1;i<=n;i++)
	{
		memset(book,0,sizeof(book));//清空上次搜索时的记忆
		if(dfs(i)==0)//寻找增广路,如果没有找到证明比最大匹配数少了,返回0 
		return 0;
	}
	return 1;
}
int main()
{
	int i,j,t=0,flag;
	while(scanf("%d",&n),n!=0)
	{
		t++;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d%d",&xmin[i],&xmax[i],&ymin[i],&ymax[i]);
		}
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&x[i],&y[i]);
		}
		memset(a,0,sizeof(a));//千万不要忘了数组清零哦 
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(x[j]>=xmin[i]&&x[j]<=xmax[i]&&y[j]>=ymin[i]&&y[j]<=ymax[i])
				a[i][j]=1;//读入边 
			}
		}
		printf("Heap %d\n",t);
		flag=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]==0)
				continue;
				a[i][j]=0;//先让此边消失,看影响最大匹配数不 
				if(connect()==0)//匹配数减少,为关键边 
				{
					if(flag==0)//处理格式问题 
					{
						flag=1;
						printf("(%c,%d)",i-1+'A',j);
					}
					else
					printf(" (%c,%d)",i-1+'A',j);
				}
				a[i][j]=1;//恢复边
			}
		}
		if(flag==0)
		printf("none");
		printf("\n\n");
	}
	return 0;
}


 

资源下载链接为: https://pan.quark.cn/s/d37d4dbee12c A:计算机视觉,作为人工智能领域的关键分支,致力于赋予计算机系统 “看懂” 世界的能力,从图像、视频等视觉数据中提取有用信息并据此决策。 其发展历程颇为漫长。早期图像处理技术为其奠基,后续逐步探索三维信息提取,与人工智能结合,又经历数学理论深化、机器学习兴起,直至当下深度学习引领浪潮。如今,图像生成和合成技术不断发展,让计算机视觉更深入人们的日常生活。 计算机视觉综合了图像处理、机器学习、模式识别和深度学习等技术。深度学习兴起后,卷积神经网络成为核心工具,能自动提炼复杂图像特征。它的工作流程,首先是图像获取,用相机等设备捕获视觉信息并数字化;接着进行预处理,通过滤波、去噪等操作提升图像质量;然后进入关键的特征提取和描述环节,提炼图像关键信息;之后利用这些信息训练模型,学习视觉模式和规律;最终用于模式识别、分类、对象检测等实际应用。 在实际应用中,计算机视觉用途极为广泛。在安防领域,能进行人脸识别、目标跟踪,保障公共安全;在自动驾驶领域,帮助车辆识别道路、行人、交通标志,实现安全行驶;在医疗领域,辅助医生分析医学影像,进行疾病诊断;在工业领域,用于产品质量检测、机器人操作引导等。 不过,计算机视觉发展也面临挑战。比如图像生成技术带来深度伪造风险,虚假图像和视频可能误导大众、扰乱秩序。为此,各界积极研究检测技术,以应对这一问题。随着技术持续进步,计算机视觉有望在更多领域发挥更大作用,进一步改变人们的生活和工作方式 。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值