Sorting Slides(poj1486,绝对匹配边)
来源:互联网 发布:软件设计方案及要求 编辑:程序博客网 时间:2024/06/05 08:26
http://poj.org/problem?id=1486
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29327#problem/E
E - Sorting Slides
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
解析:
绝对匹配边
4176 KB 16 ms C++ 1543 B
#include<string.h>#include<stdlib.h>#include<stdio.h>#include <iostream>using namespace std;const int maxn=1000+10;int map[maxn][maxn];int vis[maxn],result[maxn];int n,x[maxn],y[maxn];struct rectangle{int x1;int x2;int y1;int y2;}r[maxn];int find(int a){for(int i=1;i<=n;i++){if(map[a][i]&&!vis[i]){vis[i]=1;if(result[i]==0||find(result[i])){result[i]=a;return 1;}}}return 0;}int isok(int i,int x,int y){if(x<=r[i].x2&&x>=r[i].x1&&y>=r[i].y1&&y<=r[i].y2)return 1;elsereturn 0;}int main(){ int i,j,ca=0; while(scanf("%d",&n)!=EOF&&n!=0) { for(i=1;i<=n;i++) { scanf("%d%d%d%d",&r[i].x1,&r[i].x2,&r[i].y1,&r[i].y2); } for(i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); memset(map,0,sizeof(map)); memset(result,0,sizeof(result)); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(isok(i,x[j],y[j])) map[j][i]=1; } printf("Heap %d\n",++ca); int ans=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } if(ans<n) {printf("none\n\n");continue;}int c=0,t;for(i=1;i<=n;i++){t=result[i]; result[i]=0; map[t][i]=0;//删除边 memset(vis,0,sizeof(vis)); if(!find(t))//是否存在唯一匹配 { result[i]=t; c++; if(c>1) printf(" "); printf("(%c,%d)",i-1+'A',t); } map[t][i]=1;//恢复}if(c==0)printf("none\n\n");elseprintf("\n\n"); } //system("pause"); return 0;}
- Sorting Slides(poj1486,绝对匹配边)
- POJ1486 Sorting Slides【二分匹配】
- poj1486 Sorting Slides 二分图匹配的必须边
- poj1486 - Sorting Slides
- POJ1486:Sorting Slides
- poj1486 Sorting Slides
- POJ1486 Sorting Slides 二分图最大匹配 必要匹配
- POJ1486 Sorting Slides (二分图求最大匹配)
- POJ1486 Sorting Slides 二分图
- poj1486 sorting slides (二分图最大匹配的唯一性)
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- poj 1486 Sorting Slides(二分图匹配必要边)
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- poj 1486 Sorting Slides 二分匹配
- poj 1486 Sorting Slides(二分匹配)
- UVA 663 Sorting Slides(二分匹配)
- Poj 1486 Sorting Slides【二分匹配】
- Tour(hdu 3488,KM+拆点)
- android中进行https连接的方式
- 在windows2003上部署apache+PHP遇到的部分问题(附IIS配置FastCGI驱动PHP方法)
- 极限优化:Haar特征的另一种的快速计算方法—boxfilter
- WCF学习:关于数据类(DataContract)中逻辑方法或复写方法未被初始化的原因及解决方案
- Sorting Slides(poj1486,绝对匹配边)
- 机器学习经典算法8-树回归
- C++ STRING 和WSTRING 之间的互相转换函数
- 地面储藏室而成这样
- SQL预处理句
- 解决Eclipse中文乱码
- Java JFrame实现无边框无标题
- 《Hadoop实战(第2版)》迷你书
- inline inline-block block 三者有什么区别