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

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个矩形,里面每个分配一个数字,问唯一的数字有哪几个

思路:二分图匹配关键边判定,先求二分图匹配,再枚举去掉已匹配的每一条边,判是否匹配数减少,若减少则为关键边

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
int mat[MAXN];
int aa[MAXN];
struct area
{
int x1,x2,y1,y2;
} s[100005];
struct point
{
int x,y;
} p[100005]; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int k,n;
int cas=1;
while(~scanf("%d",&n)&&n)
{
for(int i=0; i<n; i++)
scanf("%d%d%d%d",&s[i].x1,&s[i].x2,&s[i].y1,&s[i].y2);
for(int i=0; i<n; i++)
scanf("%d%d",&p[i].x,&p[i].y);
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if(p[i].x>s[j].x1&&p[i].x<s[j].x2&&p[i].y>s[j].y1&&p[i].y<s[j].y2)
g[i][j]=1;
}
uN=vN=n;
int Match=hungary();
printf("Heap %d\n",cas++); if(Match<n)
{
printf("none\n");
continue;
}
for(int i=0; i<n; i++)
mat[i]=linker[i];
int ct=0;
for(int i=0; i<n; i++)
{
g[mat[i]][i]=0;
if(hungary()<n)
{
aa[ct++]=i;
}
g[mat[i]][i]=1;
}
if(ct==0)
printf("none\n");
else
{
int q=0;
for(int i=0; i<ct; i++)
{
if(q++)
printf(" ");
printf("(%c,%d)",'A'+aa[i],mat[aa[i]]+1);
}
printf("\n");
}
printf("\n");
}
return 0;
}

  

POJ1468 Sorting Slides的更多相关文章

  1. POJ 1486 Sorting Slides (KM)

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

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

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

  3. poj1486 Sorting Slides

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4812   Accepted: 1882 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. 有关JVM处理Java数组方法的思考

    在Java中,获取数组的长度和String的长度是两种不同的方法,这引起了本文作者的一番思考.本文从JVM的角度,探讨了Java数组在JVM中是什么对象,有哪些成员,以及声明方法. 作者:jarfie ...

  2. iserver-数据库型数据源导入后原dataset名称和数据库表名不一致的问题

    一.发现问题 系统中发现某个房屋的分层平面图查询不到 1.去sqlserver空间库中查询发现这个表‘房间_100200T001D001’不存在 2.在工作空间中查询发现是有这个数据集的 二.解决问题 ...

  3. JVM 类加载器 (二)

    1.类加载器(ClassLoader)负责加载class文件,class文件在文件开头有特定的文件标识,并且ClassLoader只负责 class 文件的加载,至于class文件是否能够运行则由Ex ...

  4. (O)阻止默认事件和阻止冒泡的应用场景

    场景1:阻止默认事件   比如这样的一个需求 点击取消a标签按钮的时候会触发一些js动作,但是不能让这个a标签产生跳转行为, 所以需要在点击取消的时候 阻止冒泡,防止其跳转. <a id='ca ...

  5. VS2010工程结构及其瘦身策略

    VS2010工程结构: 我们以在VS2010上利用MFC创建的单文档应用程序HelloWorld的文件结构为例,简述VS2010应用程序工程中文件的组成结构. 1.解决方案相关文件 解决方案相关文件包 ...

  6. Java界面编程—事件监听机制

    组件首先要先注册事件处理器,当用户单击组件.移动鼠标或者敲击键盘时都会产生事件(Event),一旦有时间发生,应用程序就会做出对该事件的响应,这些组件就是事件源(Event source). 接受.解 ...

  7. 测试 Open Live Writer

    我要试试. 看看图片如何: 这是从电脑端上传的一个例子,如果编辑器里可以支持复制粘贴图片就好了. Open Live Writer 发布以后,还可在保存在本地,想起来的时候就修改一下. 再美化一下. ...

  8. 爬虫初窥day3:BeautifulSoup

    信息提取 1.通过Tag对象的属性和方法 #!/usr/bin/python # -*- coding: utf- -*- from urllib.request import urlopen fro ...

  9. 设置默认Browser

    电信A库要求android系统中有多个Browser时,开机自动设置一个默认浏览器,而不用弹出选择框让用户手动选择. 监听开机广播Intent.ACTION_BOOT_COMPLETED, 用Pack ...

  10. spring jpetstore研究入门(zz)

    spring jpetstore研究入门 分类: java2008-12-21 23:25 561人阅读 评论(2) 收藏 举报 springstrutsibatissearchweb框架servle ...