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, 然后跑一遍最大流即可, 最大流即是最大匹配对数 ...
随机推荐
- Python 操作 GA API 指南
因为需要写一个 Blog Feature 的缘故,所以接触了下 GA 的 Python API,发现 G 家的 API 不是那么直观,比较绕,但是,在使用过程中发现其实 G 家的 API 设计挺有意思 ...
- 深度优先搜索(DFS)专题讲座PPT截图【需要原稿的请留言或私信】
以下是今晚我在bilibili直播讲DFS算法的时候的ppt截图,ppt搞了一下午,水平有限,只能做成这个样子,供大家参考!(如果需要原稿,请在评论区留言或私信告诉我,我会发到你的邮箱里),感谢各位的 ...
- POJ2407-Relatives-欧拉函数
欧拉函数: 对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. 对于一个正整数N的素数幂分解N=P1^q1*P2^q2*...*Pn^qn. Euler函数表达通式:euler(x)=x(1 ...
- Quick Brown Fox
The quick brown fox jumps over the lazy dog
- vuex使用心得分享(填坑)
今天我们简单说一下vuex的使用,vuex是什么呢,相当于react的redux,如果项目使用数据过多的话,直接管理是非常不方便的,那么采用vuex,那些繁琐的问题就迎刃而解了,首先我们先看看官方对v ...
- [国嵌笔记][004][Linux快速体验]
Linux文件系统 bin目录:可执行的程序 boot目录:与Linux启动相关的文件 dev目录:设备以文件的方式存放 etc目录:配置文件 home目录:用户文件 lib目录:与库相关的文件 ro ...
- IntelliJ IDEA 2017.3下载与安装
大约在2017年暑假的时候知道了IntelliJ IDEA,但是那个时候一心认为有Eclipse就足够用了,然而今天在网上冲浪的时候发现,IntelliJ IDEA是java语言开发的集成环境,这款开 ...
- Web前端:如何实现选择select下拉框选中跳转其他页面
<select onchange="window.location=this.value;"><option value="a.html"&g ...
- 【分享】一个集成tracert和ping的网络监测工具
最近接到一个需求,需求背景是这样的:目前Windows平台下本身都有tracert和ping的实现,而且可以直接在cmd下使用. 需求中有两个要求: 1. Windows平台中的tracert执行速度 ...
- SpringMVC,SpringBoot文件下载
前言 最近严查security, 导致原来暴露出去的s3不能用了,不允许public的s3,暂时的折中方案是自己做跳转.于是需要在SpringMVC中实现文件下载功能. 关于文件存储的设计 文件存储通 ...