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

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

Source

大致题意:
    如图,给出n个方块左上角的坐标和右下角的坐标,再给出4个数字的坐标。已知每个数字唯一的属于一个方块,求出哪些数字和方块的对应关系是必须确定的。

 
大致思路: 
    首先按照数字和方块的对应关系建立二分图(比如上图中1对应ABC,2对应AC,3对应BCD,4对应A),然后依次试着删去这些关系,再求最大匹配。如果匹配数少于n则说明这个关系必须存在。
 
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,map[N][N],x[N][],y[N][],num[N][];
int linker[N],vis[N]; int DFS(int u){
int v;
for(v=;v<=n;v++)
if(map[u][v] && !vis[v]){
vis[v]=;
if(linker[v]==- || DFS(linker[v])){
linker[v]=u;
return ;
}
}
return ;
} int Hungary(){
int u,ans=;
memset(linker,-,sizeof(linker));
for(u=;u<=n;u++){
memset(vis,,sizeof(vis));
if(DFS(u))
ans++;
}
return ans;
} int main(){ //freopen("input.txt","r",stdin); int cases=;
while(~scanf("%d",&n) && n){
memset(map,,sizeof(map));
for(int i=;i<=n;i++)
scanf("%d%d%d%d",&x[i][],&x[i][],&y[i][],&y[i][]);
for(int i=;i<=n;i++)
scanf("%d%d",&num[i][],&num[i][]);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(num[i][]>=x[j][] && num[i][]<=x[j][] && num[i][]>=y[j][] && num[i][]<=y[j][])
map[i][j]=;
printf("Heap %d\n",++cases);
int flag=;
for(int j=;j<=n;j++)
for(int i=;i<=n;i++){
if(map[i][j]==)
continue;
map[i][j]=;
if(Hungary()<n){
flag=;
char ch='A'+(j-);
printf("(%c,%d) ",ch,i);
}
map[i][j]=;
}
if(!flag)
printf("none\n\n");
else
printf("\n\n");
}
return ;
}

POJ 1486 Sorting Slides (KM)的更多相关文章

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

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

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

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

  3. poj 1486 Sorting Slides

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

  4. POJ 2400 Supervisor, Supervisee(KM)

    題目鏈接 題意 :N个部门和N个员工,每个部门要雇佣一个工人,部门对每个工人打分,从1~N,1表示很想要,N表示特别不想要,每个工人对部门打分,从1~N.1表示很想去这个部门,N表示特别不想去这个部门 ...

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

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

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

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

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

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

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

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

  9. UVA663 Sorting Slides(烦人的幻灯片)

    UVA663 Sorting Slides(烦人的幻灯片) 第一次做到这么玄学的题,在<信息学奥赛一本通>拓扑排序一章找到这个习题(却发现标程都是错的),结果用二分图匹配做了出来 蒟蒻感觉 ...

随机推荐

  1. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十二)VMW安装四台CentOS,并实现本机与它们能交互,虚拟机内部实现可以上网。

    Centos7出现异常:Failed to start LSB: Bring up/down networking. 按照<Kafka:ZK+Kafka+Spark Streaming集群环境搭 ...

  2. C++之new、delete 与malloc、free的异同

    在C/C++编程中常常会申请内存.而对内存的申请释放操作有两套方法: new.delete 与malloc.free.他们的使用最好是成对使用,不要去混搭---这可不是时尚界哦. 例如以下是这两组方法 ...

  3. mongodb的用法

    关于新版(2.***)的c#用法,网上基本没有.昨天折腾半天,去构造server,发现现在新版本不需要了,文档是这样的,大概意思,无需像原来那样获取server,直接从client获取db就行了. h ...

  4. Direct2D教程VII——变换几何(TransformedGeometry)对象

    目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

  5. var, object, dynamic的区别以及使用

    var, object, dynamic的区别以及使用 阅读目录: 一. 为什么是它们三个 二. 能够任意赋值的原因 三. dynamic的用法 四. 使用dynamic的注意事项 拿这三者比较的原因 ...

  6. Jquery——几个注意的小知识

    event.stopPropagation() 停止事件冒泡 event.preventDefault()//组织默认行为(例如错误的时候,阻止按钮提交) event.type获取事件类型 event ...

  7. Java 生成ZIP文件

    public static byte[] fileToZip(){ ZipOutputStream append = null; ByteArrayOutputStream bos = new Byt ...

  8. JS 处理Json数据事例

    JS从远端获取数据之后,往往还需要在处理一下,下面给出一个事例,供参考 将'[{"role_id":1,"enable":1},{"role_id&q ...

  9. SQL Server还原数据库

    http://www.cnblogs.com/ggll611928/p/6377545.html 恢复数据库: 1.分离数据库以断开当前的访问连接. 2.附加数据库mdf文件. 3.执行RESTORE ...

  10. 自己定义RatingBar,能依据设置改变样式

    项目在我的GITHUB上  mirsfang的GitHub 一个简单的自己定义View  ,为了一个 比較奇葩的需求而搞出来的.他的功能就是能让你自己设置图片和图片的大小以及星星的数量,是一个组合型的 ...