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 , B has number , C number  and A number . 

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 , the next pair for , etc. No number will lie on a slide boundary. 

The input is terminated by a heap description starting with n = , 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


Sample Output

Heap
(A,) (B,) (C,) (D,) Heap
none

Source

 
给出一些矩形的坐标和一些点的坐标,若点在矩形内,则该点和该矩形匹配,问是否存在某个匹配在所有的完美匹配中,这题可以先任意找出一个完美匹配,然后依次删除该匹配的每一条边,若仍能构成完美匹配,则这个匹配不唯一,若不能构成完美匹配,则该匹配唯一
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100
int n;
int x1[N],x2[N],y1[N],y2[N];
int mp[N][N];
int match[N];
int path[N];
int vis[N];
bool dfs(int x){
for(int i=;i<n;i++){
if(!vis[i] && mp[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
int solve(){
int ans=;
memset(match,-,sizeof(match)); for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
}
return ans;
}
int main()
{
int ac=;
while(scanf("%d",&n)== && n){
printf("Heap %d\n",++ac);
for(int i=;i<n;i++){
scanf("%d%d%d%d",&x1[i],&x2[i],&y1[i],&y2[i]);
}
memset(mp,,sizeof(mp));
for(int i=;i<n;i++){
int a,b;
scanf("%d%d",&a,&b);
for(int j=;j<n;j++){
if(a>x1[j] && a<x2[j] && b>y1[j] && b<y2[j]){
mp[i][j]=;
}
}
} int ans=solve();
//printf("===%d\n",ans);
int flag=;
if(ans==n){
for(int i=;i<n;i++){
path[i]=match[i];
}
for(int i=;i<n;i++){
int u=path[i];
mp[u][i]=;//这个表示匹配的每一条边?
if(solve()==n) continue;
else{
if(flag)
printf(" ");
printf("(%c,%d)",'A'+i,path[i]+);
flag=;
}
mp[u][i]=; }
}
if(!flag){
printf("none");
}
printf("\n\n"); }
return ;
}

poj 1486 Sorting Slides(二分图匹配的查找应用)的更多相关文章

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

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

  2. POJ 1486 Sorting Slides(二分图完全匹配必须边)题解

    题意:给你n张照片的范围,n个点的坐标,问你能唯一确定那几个点属于那几张照片,例如样例中4唯一属于A,2唯一属于C,1唯一属于B,3唯一属于C 思路:进行二分图完全匹配,怎么判断唯一属于?匹配完之后删 ...

  3. POJ 1486 Sorting Slides (KM)

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2831   Accepted: 1076 De ...

  4. poj 1486 Sorting Slides

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4469   Accepted: 1766 De ...

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

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

  6. POJ 1486 Sorting Slides【二分图匹配】

    题目大意:有n张幻灯片和n个数字,幻灯片放置有重叠,每个数字隶属于一个幻灯片,现在问你能够确定多少数字一定属于某个幻灯片 思路:上次刷过二分图的必须点后这题思路就显然了 做一次二分匹配后将当前匹配的边 ...

  7. POJ 1486 Sorting Slides(寻找必须边)

    题意:找出幻灯片与编号唯一对应的情况 思路: 1:求最大匹配,若小于n,则答案为none,否则转2 (不过我代码没有事先判断一开始的最大匹配数是否<n,但这样也过了,估计给的数据最大匹配数一定为 ...

  8. POJ 3057 Evacuation(二分图匹配+BFS)

    [题目链接] http://poj.org/problem?id=3057 [题目大意] 给出一个迷宫,D表示门,.表示人,X表示不可通行, 每个门每时间单位只允许一个人通过, 每个人移动一格的为一时 ...

  9. POJ 3041 Asteroids (二分图匹配)

    [题目链接] http://poj.org/problem?id=3041 [题目大意] 一个棋盘上放着一些棋子 每次操作可以拿走一行上所有的棋子或者一列上所有的棋子 问几次操作可以拿完所有的棋子 [ ...

随机推荐

  1. DB2完美卸载

    会安装,也要会卸载.详细的安装说明不多,我这个我觉得写得还算全.  准备工作.      1.用 ps -ef|grep db2 找出db2安装目录      2. ./db2level 查出DB2的 ...

  2. DELL RACADM 工具使用介绍

    如果iDRAC的IP或者设置出现问题,不能够链接,那么可以通过RACADM这个程序在系统层面可以对iDRAC进行设置,使用的方法以及命令都在下边. RACADM provides command li ...

  3. 使用ICallbackEventHandler接口更高效实现Ajax

    使用ICallbackEventHandler接口可以方便地高效地实现Ajax功能 1.处理页面需实现ICallbackEventHandler接口,此接口有两个方法 a.GetCallbackRes ...

  4. (转)JQuery处理json与ajax返回JSON实例

    son数据是一种经型的实时数据交互的数据存储方法,使用到最多的应该是ajax与json配合使用了,下面我来给大家介绍jquery处理json数据方法. 一.JSON的一些基础知识. JSON中对象通过 ...

  5. linux 各种发行版及包管理器的关系

    linux 各种发行版及包管理器的关系 Linux发行版列表 基于Kpkg(Debian 系) Debian GNU / Linux 及其派生发行版使用deb软件包格式,并使用dpkg及其前端作为包管 ...

  6. C#中的委托是什么?

    概述 委托类似C++中的函数指针,但是又有所不同.在C++中,函数指针不是类型安全的,它指向的是内存中的某一个位置,我们无法判断这个指针实际指向什么,对于参数和返回类型就更难以知晓.而.NET的委托则 ...

  7. DOM 添加 / 更新 / 删除 XML (CURD)

    获得Document /**     * 获取文档     * 1.获得实例工厂     * 2.获得解析器     * 3.获得document     */ 添加结点 /**     * 1.获得 ...

  8. JQuery 判断ie7|| ie8

    if( $.browser.msie && ( $.browser.version == '7.0' || $.browser.version == '8.0'|| $.browser ...

  9. C 语言 联合union初见

    1.什么是联合? “联合”是一种构造类型的数据结构.在一个“联合”内可以定义多种不同的数据类型, 一个被说明为该“联合”类型的变量中,允许装入该“联合”所定义的任何一种数据,这些数据共享同一段内存,已 ...

  10. Responder一点也不神秘————iOS用户响应者链完全剖析

    一.事件分类 对于IOS设备用户来说,他们操作设备的方式主要有三种:触摸屏幕.晃动设备.通过遥控设施控制设备.对应的事件类型有以下三种: 1.触屏事件(Touch Event) 2.运动事件(Moti ...