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

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

Southwestern European Regional Contest 1998

Solution

题意就是找所有可以唯一对应起来的矩形和数字。

看起来这种对应关系很像二分图匹配??

建成二分图后就变成判定哪些边是必须的了。必须的意思是删掉这条边最大匹配数会变小,所以对所有边删边后做一次最大匹配,与最初始的最大匹配数进行比较即可。

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; int n, vis[], to[], pi[];
int xi[], xa[], yi[], ya[]; bool check(int x, int y, int i) {
if(x >= xi[i] && x <= xa[i] && y >= yi[i] && y <= ya[i]) return ;
return ;
} int G[][]; bool dfs(int u) {
for(int v = ; v <= n; v ++) {
if(G[u][v]) {
if(!vis[v]) {
vis[v] = ;
if(!pi[v] || dfs(pi[v])) {
pi[v] = u;
to[u] = v;
return ;
}
}
}
}
return ;
} int match() {
memset(to, , sizeof(to));
memset(pi, , sizeof(pi));
int ans = ;
for(int i = ; i <= n; i ++) {
if(!to[i]) {
memset(vis, , sizeof(vis));
ans += dfs(i);
}
}
return ans;
} int main() {
int ti = ;
while(~scanf("%d", &n)) {
if(n == ) break;
memset(G, , sizeof(G));
for(int i = ; i <= n; i ++)
scanf("%d%d%d%d", &xi[i], &xa[i], &yi[i], &ya[i]);
for(int i = ; i <= n; i ++) {
int x, y;
scanf("%d%d", &x, &y);
for(int j = ; j <= n; j ++) {
if(!check(x, y, j)) continue;
G[j][i] = ;
}
}
int ma = match(); int flag = ;
printf("Heap %d\n", ++ ti);
for(int i = ; i <= n; i ++) {
for(int j = ; j <= n; j ++)
if(G[i][j]) {
G[i][j] = ;
if(match() < ma) {
printf("(%c,%d) ", i + , j);
flag = ;
}
G[i][j] = ;
}
}
if(!flag) printf("none\n\n");
else printf("\n\n");
}
return ;
}

【POJ】1486:Sorting Slides【二分图关键边判定】的更多相关文章

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

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

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

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

  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个点的坐标,问你能唯一确定那几个点属于那几张照片,例如样例中4唯一属于A,2唯一属于C,1唯一属于B,3唯一属于C 思路:进行二分图完全匹配,怎么判断唯一属于?匹配完之后删 ...

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

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

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

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

  9. POJ1468 Sorting Slides

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4442   Accepted: 1757 De ...

随机推荐

  1. weblogica 目录结构 简单介绍 创建domain domain所在目录

    1. samples 创建过程略过 domain的目录 [weblogic@node2 base_domain]$ pwd /home/weblogic/Oracle/Middleware/Oracl ...

  2. css给表格每一列设置不同的样式

    第一列#id table tr td:first-child{ overflow: visible; }第二列table tr td:first-child+td{color:#666;}第三列tab ...

  3. Interger不可变原理

    1.先看代码: package main.java.db.mq; public class TestSwap { public static void main(String[] args) { In ...

  4. SQL自定义排序 ORDER BY

    将id为30002 排在最前面 50第二 其他 不变 SELECT TOP 10 * FROM [表名] t1 ORDER BY case t1.ID when 30002 then 0 WHEN 5 ...

  5. 002_Linux-Memory专题

    一.单独查看某个进程的内存占用 pmap 736 | tail -n 1 二. 以前我对这块认识很模糊,而且还有错误的认识:今天由我同事提醒,所以我决定来好好的缕缕这块的关系. 图: -------- ...

  6. Gitlab权限管理

    使用管理员登陆gitlab(版本为8.9)创建一个组 给用户授权 创建新用户 再创建两个dev1和dev2 然后再到项目界面授权给pm授权master 创建库(事先先建一个java组) 设置权限 创建 ...

  7. poj1102

    模拟 #include <iostream> #include <string> using namespace std; ][][] = { { ' ', '-', ' ', ...

  8. 03 Editor plugins and IDEs 编辑器插件和 ide

    Editor plugins and IDEs  编辑器插件和 ide Introduction  介绍 Options 选项   Introduction 介绍 This document list ...

  9. Flask:操作SQLite3(0.1)

    Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 本文介绍了第一次在Flask框架中操作SQLite3数据库的测试,参考了官网的文档Using SQLite 3 wit ...

  10. Java---容器基础总结

    Java提供了大量持有对象的方式: (1) 数组将数字与对象联系起来. 它保存类型明确的对象,查询对象时,不需要对结果做类型转换.它可以是多维的, 可以保存基本类型的数据. 但是,数组一旦生成,其容量 ...