Sorting Slides(二分图匹配——确定唯一匹配边)
题目描述:
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
/*
题意描述:输入幻灯片的坐标位置,页码的坐标位置,将能唯一确定页码的幻灯片按照顺序输出,
如果没有一张能够唯一确定则输出none
*/
/*
解题思路:基本思路是将幻灯片和页码进行匹配,按照二分图匹配的思路求最大匹配,如果某一条边
是唯一边,则将这条边去掉以后,该二分图的最大匹配数将<n,输出该匹配边。
*/
#include<stdio.h>
#include<string.h>
const int N=;
struct Slide{
int xmin,xmax,ymin,ymax;
}slide[N];
struct Num{
int x,y;
}num[N];
int n,e[N][N],cx[N],cy[N],bk[N];
int maxmatch();
int path(int u); int main()
{
int i,j,t=;
while(scanf("%d",&n), n != )
{
for(i=;i<n;i++)
scanf("%d%d%d%d",&slide[i].xmin,&slide[i].xmax,&slide[i].ymin,&slide[i].ymax);
for(i=;i<n;i++)
scanf("%d%d",&num[i].x,&num[i].y); memset(e,,sizeof(e));
for(i=;i<n;i++){
for(j=;j<n;j++){
if(num[i].x>slide[j].xmin && num[i].x<slide[j].xmax
&& num[i].y>slide[j].ymin && num[i].y<slide[j].ymax)
e[j][i]=;//点i在j张里,按照输出顺序,先输出字母,再输出数字
}
} printf("Heap %d\n",++t);
int flag=;
for(i=;i<n;i++){
for(j=;j<n;j++){
if(e[i][j])
{
e[i][j]=;
if(maxmatch() < n)
{
if(flag)
printf(" (%c,%d)",'A'+i,j+);
else
printf("(%c,%d)",'A'+i,j+);
flag=;
}
e[i][j]=;
}
}
} if(flag)
printf("\n\n");
else
printf("none\n\n");
}
return ;
} int maxmatch()
{
int i;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
int ans=;
for(i=;i<n;i++)
{
if(cy[i]==-)
{
memset(bk,,sizeof(bk));
ans += path(i);
}
}
return ans;
}
int path(int u)
{
int i;
for(i=;i<n;i++)
{
if(e[u][i] && !bk[i])
{
bk[i]=;
if(cx[i]==- || path(cx[i]))
{
cx[i]=u;
cy[u]=i;
return ;
}
}
}
return ;
}
/*易错分析:按照输出顺序,先幻灯片再页码,所以输入边的时候j在前,i在后*/
Sorting Slides(二分图匹配——确定唯一匹配边)的更多相关文章
- poj 1486 Sorting Slides(二分图匹配的查找应用)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- POJ 1486 Sorting Slides (二分图关键匹配边)
题意 给你n个幻灯片,每个幻灯片有个数字编号1~n,现在给每个幻灯片用A~Z进行编号,在该幻灯片范围内的数字都可能是该幻灯片的数字编号.问有多少个幻灯片的数字和字母确定的. 思路 确定幻灯片的数字就是 ...
- POJ 1486 Sorting Slides(二分图匹配)
[题目链接] http://poj.org/problem?id=1486 [题目大意] 给出每张幻灯片的上下左右坐标,每张幻灯片的页码一定标在这张幻灯片上, 现在问你有没有办法唯一鉴别出一些幻灯片 ...
- 【POJ】1486:Sorting Slides【二分图关键边判定】
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5390 Accepted: 2095 De ...
- UVa 1349 (二分图最小权完美匹配) Optimal Bus Route Design
题意: 给出一个有向带权图,找到若干个圈,使得每个点恰好属于一个圈.而且这些圈所有边的权值之和最小. 分析: 每个点恰好属于一个有向圈 就等价于 每个点都有唯一后继. 所以把每个点i拆成两个点,Xi ...
- 二分图匹配之最佳匹配——KM算法
今天也大致学了下KM算法,用于求二分图匹配的最佳匹配. 何为最佳?我们能用匈牙利算法对二分图进行最大匹配,但匹配的方式不唯一,如果我们假设每条边有权值,那么一定会存在一个最大权值的匹配情况,但对于KM ...
- UVA 1349 Optimal Bus Route Design (二分图最小权完美匹配)
恰好属于一个圈,那等价与每个点有唯一的前驱和后继,这让人想到了二分图, 把一个点拆开,点的前驱作为S集和点的后继作为T集,然后连边,跑二分图最小权完美匹配. 写的费用流..最大权完美匹配KM算法没看懂 ...
- 紫书 例题11-10 UVa 1349 (二分图最小权完美匹配)
二分图网络流做法 (1)最大基数匹配.源点到每一个X节点连一条容量为1的弧, 每一个Y节点连一条容量为1的弧, 然后每条有向 边连一条弧, 容量为1, 然后跑一遍最大流即可, 最大流即是最大匹配对数 ...
随机推荐
- SPRINGBOOT 读书笔记
Spring基础 Spring的发展 xml配置 注解配置 Java配置 Spring模块:核心容器 AOP 消息 web 数据访问集成 常用的:@Component @Service @Reposi ...
- 我的第六个网页制作:table标签
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- [bzoj1369] [Baltic2003]Gem
结论题...一棵树里用到的颜色数不超过logn.. f[i][j]表示以i为根的子树里,i的颜色是j的方案数. g[i][j]表示max{f[i][k]},(k!=j #include<cstd ...
- HDU5752-Sqrt Bo
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- jsp的内置对象
JSP内置对象即无需声明就可以直接使用的对象实例,在实际的开发过程中,比较常用的JSP对象有request,response,session,out和application等,笔者在本文章中将简单介绍 ...
- c++(排序二叉树线索化)
前面我们谈到了排序二叉树,还没有熟悉的同学可以看一下这个,二叉树基本操作.二叉树插入.二叉树删除1.删除2.删除3.但是排序二叉树也不是没有缺点,比如说,如果我们想在排序二叉树中删除一段数据的节点怎么 ...
- nagios与zabbix对比
nagios与zabbix对比 web功能: Nagios简单直观,报警与数据都在同一页面,***.红色即为问题项.Nagios web端不要做任何配置. Zabbix监控数据与报警是分开的,查看问题 ...
- mysql 手册关于修改列字符编码的一个bug
项目因为历史原因使用了 GBK编码,遇到非GBK编码字符时出现乱码问题,情况比较严重,暂时先打算修改 列的字符编码为 utf8mb4. 查看 mysql 手册: 用 GBK 编码转 utf8 进行说明 ...
- load和DOMContenLoaded的区别
load和DOMContentLoaded的作用就是当页面加载完成的时候自动执行,但他们执行的时间点是不一样的. DOM文档加载步骤: (1)解析html结构 (2)加载外部脚本和样式表文件 (3)解 ...
- sublime text如何保存为uft-8无bom编码格式文件
https://jingyan.baidu.com/article/9158e000388092a2541228b6.html 今天发现自己的文件突然多了很多特殊符号,真是奇了怪,查找html里面也并 ...