题目描述:

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(二分图匹配——确定唯一匹配边)的更多相关文章

  1. poj 1486 Sorting Slides(二分图匹配的查找应用)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  2. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  3. POJ 1486 Sorting Slides (二分图关键匹配边)

    题意 给你n个幻灯片,每个幻灯片有个数字编号1~n,现在给每个幻灯片用A~Z进行编号,在该幻灯片范围内的数字都可能是该幻灯片的数字编号.问有多少个幻灯片的数字和字母确定的. 思路 确定幻灯片的数字就是 ...

  4. POJ 1486 Sorting Slides(二分图匹配)

    [题目链接] http://poj.org/problem?id=1486 [题目大意] 给出每张幻灯片的上下左右坐标,每张幻灯片的页码一定标在这张幻灯片上, 现在问你有没有办法唯一鉴别出一些幻灯片 ...

  5. 【POJ】1486:Sorting Slides【二分图关键边判定】

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5390   Accepted: 2095 De ...

  6. UVa 1349 (二分图最小权完美匹配) Optimal Bus Route Design

    题意: 给出一个有向带权图,找到若干个圈,使得每个点恰好属于一个圈.而且这些圈所有边的权值之和最小. 分析: 每个点恰好属于一个有向圈 就等价于 每个点都有唯一后继. 所以把每个点i拆成两个点,Xi  ...

  7. 二分图匹配之最佳匹配——KM算法

    今天也大致学了下KM算法,用于求二分图匹配的最佳匹配. 何为最佳?我们能用匈牙利算法对二分图进行最大匹配,但匹配的方式不唯一,如果我们假设每条边有权值,那么一定会存在一个最大权值的匹配情况,但对于KM ...

  8. UVA 1349 Optimal Bus Route Design (二分图最小权完美匹配)

    恰好属于一个圈,那等价与每个点有唯一的前驱和后继,这让人想到了二分图, 把一个点拆开,点的前驱作为S集和点的后继作为T集,然后连边,跑二分图最小权完美匹配. 写的费用流..最大权完美匹配KM算法没看懂 ...

  9. 紫书 例题11-10 UVa 1349 (二分图最小权完美匹配)

    二分图网络流做法 (1)最大基数匹配.源点到每一个X节点连一条容量为1的弧, 每一个Y节点连一条容量为1的弧, 然后每条有向 边连一条弧, 容量为1, 然后跑一遍最大流即可, 最大流即是最大匹配对数 ...

随机推荐

  1. wifi入侵思路

    一.得到wifi密码   系统:Kali Linux   工具:Aircrack-ng,EWSA   方法:   1.WEP加密:deauth攻击:得到足够报文直接破解.   2.WPA加密:deau ...

  2. [Link-Cut-Tree]【学习笔记】

    可以按照<Utopiosphere>的调唱出来 “Link-Cut ,Time doesn’t stop .Prepare your doubts ,Eat them up” 参考资料: ...

  3. hdu_2089(数位dp)

    hdu_2089(数位dp) 标签: dp 我初次接触数位dp表面上看上去挺简单,但是仔细学还是要考虑很多细节的.wa了无数次,这里引入一个 很好地博客 #include<cstdio> ...

  4. 如何给虚拟主机安装phpMyAdmin

    很多虚拟主机没有phpMyAdmin,例如阿里云的云虚拟主机默认的数据库管理工具是DMS,这样好多朋友管理数据库时会觉得不方便.phpMyAdmin是比较大众和常用的Mysql数据库管理软件,我们可以 ...

  5. Solr6.0与Jetty、Tomcat在Win环境下搭建/部署

    摘要: Solr6的新特性包括增强的edismax,对SQL更好的支持--并行SQL.JDBC驱动.更多的SQL语法支持等,并且在Solr6发布以后,Solr5还在持续更新,对于想尝鲜Solr6的用户 ...

  6. Linux下C++/C的编译调试

    这几天因为任务的原因我需要在ubuntu下编写程序.因此恶补了许多linux程序编写的知识.我分以下几个方面总结我所学的知识. gcc,g++,make命令的使用 gdb 调试 VScode的使用 c ...

  7. BC高精确度函数使用。

    bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(string $left_operand, string ...

  8. webzip怎么用 如何用webzip下载整个网站?

    相信很多站长对webzip这款软件都并不感到陌生,它功能强大,能够完整下载网站的内容,或者你也可以选择自行设置下载的层数.文件类型.网页与媒体文件的定位等等.具体详情你可以在百度上去搜一下.由于web ...

  9. 开始学习 Backbone

    [转]开始学习 Backbone 如何将模型-视图-控制器 (MVC) 架构引入 Ajax Web 应用程序 如何高效管理 Web 应用程序中的数目众多的 JavaScript 代码行是一个挑战.As ...

  10. scss 初学笔记 三 继承

    //继承 .btn{ padding: 4px 10px; font-size: 14px; } .primary{ background:red; @extend .btn; } //%placeh ...