POJ 1486 Sorting Slides 最大二分匹配 匈牙利算法
来源:互联网 发布:ios脚本软件 编辑:程序博客网 时间:2024/06/05 11:06
Sorting Slides
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3780 Accepted: 1480
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.
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.
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.
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
先做一边最大二分匹配。题目问的是这个匹配是否是确定的。那么只要去掉他们匹配的线再做一次,如果最大二分匹配还是和原先的最大二分匹配一样那说明这个匹配是可变的。不是唯一的。。如果不相等的话。说明匹配是唯一的
#include<stdio.h>#include<string.h>struct orzcfx{int x1;int x2;int y1;int y2;};struct orzpoint{int x;int y;};int n,m;int cc[1111];bool imap[1111][1111],d[1111]; int s[1111]; bool findOrz(int k){ int i; for(i=0;i<n;i++){ if(!d[i]&&imap[k][i]){ d[i]=1; if(s[i]==-1||findOrz(s[i])){ s[i]=k; return true; } } } return false; } int main(){ orzcfx cfx[1111]; int i,j,k,l,t1,t2,t,orz; int cas=1; int x,y; while(~scanf("%d",&n)&&n){ memset(imap,0,sizeof(imap)); memset(cc,0,sizeof(cc)); memset(s,-1,sizeof(s));for(i=0;i<n;i++){scanf("%d%d%d%d",&cfx[i].x1,&cfx[i].x2,&cfx[i].y1,&cfx[i].y2);} for(i=0;i<n;i++){scanf("%d%d",&x,&y);for(j=0;j<n;j++){ //判断序号是否在里面 if(x>cfx[j].x1 &&x<cfx[j].x2 &&y>cfx[j].y1 &&y<cfx[j].y2){imap[i][j]=1;}}}int ans=0;int orzjud=0;int flag=0;for(i=0;i<n;i++){memset(d,0,sizeof(d));if(findOrz(i)){ans++;}}for(i=0;i<n;i++){cc[i]=s[i];//printf("%d ",s[i]);}printf("Heap %d\n", cas++); /*for(int ii=0;ii<n;ii++){for(int jj=0;jj<n;jj++){printf("%d " ,imap[ii][jj]);}printf("\n");}*/if(ans==n) { for(i=0;i<n;i++) { memset(s,-1,sizeof(s)); imap[cc[i]][i]=0; //删边 /*for(int ii=0;ii<n;ii++){for(int jj=0;jj<n;jj++){printf("%d " ,imap[ii][jj]);}printf("\n");}*/ int orzfind= 0; for(j=0;j<n;j++){ memset(d,0,sizeof(d)); if(findOrz(j)) orzfind++; } if(orzfind==n) continue; else { if(flag) printf(" "); printf("(%c,%d)",'A'+i,cc[i]+1); flag=1; } imap[cc[i]][i]=1; } } if(!flag) printf("none"); printf("\n\n"); }}
0 0
- POJ 1486 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(二分匹配)
- Poj 1486 Sorting Slides【二分匹配】
- POJ 1486 Sorting Slides 二分匹配变形 完全匹配
- poj 1486 Sorting Slides 二分匹配唯一性判定
- POJ - 1486 Sorting Slides 二分图 完美匹配
- poj 1486 Sorting Slides(二分图匹配必要边)
- poj 1486 Sorting Slides(二分图匹配)
- POJ1486 Sorting Slides 二分图最大匹配 必要匹配
- POJ1486 Sorting Slides (二分图求最大匹配)
- POJ1486 Sorting Slides【二分匹配】
- 匈牙利算法-最大二分匹配
- 二分最大匹配--匈牙利算法
- linux下c环境搭建
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
- 方法重写
- 理解矩阵乘法
- 费米估算法有什么用
- POJ 1486 Sorting Slides 最大二分匹配 匈牙利算法
- Unable to start the Genymotion virtual device.
- 实现 oracle数据库转意数据到Mysql,最简单最直接
- Hibernate 所有缓存机制详解
- java的Class对象详解
- HDOJ1159 Common Subsequence(dp)
- free -M解读
- IOS上拉下拉刷新之详解
- JS学习