博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1486 Sorting Slides (KM)
阅读量:6239 次
发布时间:2019-06-22

本文共 3684 字,大约阅读时间需要 12 分钟。

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

46 22 10 204 18 6 168 20 2 1810 24 4 89 1519 1711 721 1120 2 0 20 2 0 21 11 10

Sample Output

Heap 1(A,4) (B,1) (C,2) (D,3)Heap 2none

Source

 

大致题意:

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

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

 

转载地址:http://qfdia.baihongyu.com/

你可能感兴趣的文章
M端计算rem方法
查看>>
as3 用StyleSheet css 设置文本样式
查看>>
hdu4612(双连通缩点+树的直径)
查看>>
【转】深入理解 C# 协变和逆变
查看>>
第六次作业
查看>>
UML
查看>>
9.[Java开发之路](6)File类的使用
查看>>
折半插入排序(binary insertion sort)
查看>>
打包常见问题
查看>>
javascript解析json
查看>>
在Ubuntu下编译WebKit源码
查看>>
amazeui 移动开发
查看>>
python2 与python3中最大的区别(编码问题bytes&str
查看>>
HDU 2243 AC自动机+DP+矩阵
查看>>
什么叫脱字符合^
查看>>
git版本控制管理实践-2
查看>>
HTTP基础知识(三)
查看>>
如何有效释放DB2所占的磁盘空间?
查看>>
三分法
查看>>
第 8 章 容器网络 - 058 - flannel 概述
查看>>