Sorting Slides
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4812   Accepted: 1882

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个矩形的坐标和n个点的坐标,每个矩形上最多只能有一个点,问是否有点一定属于某个矩形.
分析:矩形与点配对,非常像是二分图匹配.最后要求的实际上是二分图的最大匹配中必须留下的边.因为最大匹配找的边是删掉以后很容易使得匹配数变小的边,所以枚举最大匹配中的边,删掉后看看最大匹配数是否减小,如果是,那么这条边就是必须的.
          犯了一个错:两个dfs函数弄混了,导致在第二个dfs函数中调用了第一个函数QAQ,以后这种函数还是根据功能来命名的好.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,a[][],pipei[],flag[],can[][],cnt,ans[][],cas;
int pipei2[];
bool print = false;
struct node
{
int minx,maxx,miny,maxy;
} e[];
struct node2
{
int x,y;
} point[]; bool dfs(int u)
{
for (int i = ; i <= n; i++)
if (a[u][i] && !flag[i])
{
flag[i] = ;
if (!pipei[i] || dfs(pipei[i]))
{
pipei[i] = u;
return true;
}
}
return false;
} bool dfs2(int u)
{
for (int i = ; i <= n; i++)
if (a[u][i] && !flag[i])
{
flag[i] = ;
if (!pipei2[i] || dfs2(pipei2[i]))
{
pipei2[i] = u;
return true;
}
}
return false;
} int main()
{
while (scanf("%d",&n) && n)
{
memset(pipei,,sizeof(pipei));
memset(can,,sizeof(can));
memset(ans,,sizeof(ans));
memset(a,,sizeof(a));
cnt = ;
print = false;
for (int i = ; i <= n; i++)
scanf("%d%d%d%d",&e[i].minx,&e[i].maxx,&e[i].miny,&e[i].maxy);
for (int i = ; i <= n; i++)
scanf("%d%d",&point[i].x,&point[i].y);
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
if (point[j].x >= e[i].minx && point[j].x <= e[i].maxx && point[j].y >= e[i].miny && point[j].y <= e[i].maxy)
a[j][i] = ;
for (int i = ; i <= n; i++)
{
memset(flag,,sizeof(flag));
if (dfs(i))
cnt++;
}
for (int i = ; i <= n; i++)
{
a[pipei[i]][i] = ;
int cnt2 = ;
memset(pipei2,,sizeof(pipei2));
for (int j = ; j <= n; j++)
{
memset(flag,,sizeof(flag));
if(dfs2(j))
cnt2++;
}
if (cnt2 < cnt)
ans[i][pipei[i]] = ;
a[pipei[i]][i] = ;
}
printf("Heap %d\n",++cas);
for (int i = ; i <= n; i++)
if (ans[i][pipei[i]])
{
print = true;
printf("(%c,%d) ",'A' + i - ,pipei[i]);
}
if (!print)
printf("none");
printf("\n\n");
} return ;
}

poj1486 Sorting Slides的更多相关文章

  1. POJ1468 Sorting Slides

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

  2. POJ 1486 Sorting Slides (KM)

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

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

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

  4. poj 1486 Sorting Slides

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

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

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

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

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

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

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

  8. Sorting Slides(二分图匹配——确定唯一匹配边)

    题目描述: Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not ...

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

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

随机推荐

  1. sqli-labs学习笔记 DAY3

    DAY 3 sqli-labs lesson 6 同lesson 5,只是把单引号改为双引号 sqli-labs lesson 7 同lesson 5,只是把单引号后面加两个空格,使用Burpsuit ...

  2. 华为笔试——C++特定位数比较

    题目:特定位数比较 题目介绍:输入两行数据,第一行为 m 个正整数,以空格隔开:第二行为正整数 n ,且 n<= m:要求对第一行的数字的后三位大小进行排序,输出排行 n 的数字,其中,若不满三 ...

  3. 当Kubernets遇上阿里云 -之七层负载均衡(一).

    我们知道Kubernetes的service只能实现基于4层的负载均衡,无法提供7层之上的许多特性,诸如基于URL的负载均衡,SSL支持,三方授权等等:Ingress可以实现七层负载均衡的许多功能,唯 ...

  4. ViewPort <meta>标记

    ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...

  5. scrum立会报告+燃尽图(第三周第七次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...

  6. 04慕课网《进击Node.js基础(一)》HTTP讲解

    HTTP:通信协议 流程概述: http客户端发起请求,创建端口默认8080 http服务器在端口监听客户端请求 http服务器向客户端返回状态和内容 稍微详细解析: 1.域名解析:浏览器搜素自身的D ...

  7. .net组件和com组件&托管代码和非托管代码

    com组件和.net组件: COM组件是非托管对象,可以不需要.NET框架而直接运行,.NET框架组件是托管对象,必须有.NET框架的支撑才能运行. COM组件有独立的类型库文件,而.NET组件是通过 ...

  8. 线段树---成段更新hdu1698 Just a Hook

    hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...

  9. C语言之goto浅析

    1.  读代码时遇了的疑惑点: static int do_bind(const char *host, int port, int protocol, int *family) { int fd; ...

  10. Spring中jdbc Template使用

    http://1358440610-qq-com.iteye.com/blog/1826816