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. html js div随鼠标移动

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. 从零开始的Python学习Episode 8——深浅拷贝

    深浅拷贝 一.浅拷贝 列表中存储的是数据的内存地址,当我们要查询或修改列表中的数据时,我们是通过列表中的地址找到要访问的内存.当我们修改列表中的数据时,如果修改的是一个不可变类型(整型,长整型,浮点数 ...

  3. Tim Cook在电话会议上宣布,Burberry前CEO Angela Ahrendts将在下周加入苹果

    在今天的第二季度财报电话会议上,苹果公司的 CEO Tim Cook 宣布 Burberry 的前 CEO Angela Ahrendts 将在下周入职苹果,出任苹果负责零售和网上商店的高级副总裁. ...

  4. oozie的shell-action中加入hive脚本命令启动执行shell同时操作hive,抛异常Container killed on request. Exit code is 143 Container exited with a non-zero exit code 143

    使用oozie来调度操作,用shell的action执行命令,其中shell里包含着hive -e 操作执行时,oozie窗口报 WARN ShellActionExecutor: - SERVER[ ...

  5. node.js常用方法

    1.获取真实地址 function getClientIp(req) { return req.headers['x-forwarded-for'] || req.connection.remoteA ...

  6. 求1到N(正整数)之间1出现的个数

    一.题目要求 给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数. 要求: 写一个函数 f(N) ,返回1 到 N 之间出现的“1”的个数.例如 f(12)  = 5 ...

  7. 第六周PSP &进度条

    团队项目PSP 一.表格:     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论alpha完成情况并总结 9:40 11:20 17 ...

  8. 【Leetcode】445. Add Two Numbers II

    You are given two non-empty linked lists representing two non-negative integers. The most significan ...

  9. windows查看端口占用指令

    1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\>netstat -ano 协议    本地地址                     外部地址  ...

  10. Java NIO:IO与NIO的区别 -阿里面试题

    一.概念 NIO即New IO,这个库是在JDK1.4中才引入的.NIO和IO有相同的作用和目的,但实现方式不同,NIO主要用到的是块,所以NIO的效率要比IO高很多.在Java API中提供了两套N ...