poj1486Sorting Slides【二分图匹配判断是否是必须】
来源:互联网 发布:战国水晶杯 知乎 编辑:程序博客网 时间:2024/05/21 15:39
Sorting Slides
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 4176 Accepted: 1619
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
Source
Southwestern European Regional Contest 1998
题意:rt
做法:记录之前的路径,设每条边不存在,如果最大匹配数仍是n,那么这个边不是必须边
注意 xy不要弄反了
#include <iostream>#include <stdio.h>#include <string.h>#define M 1000#define inf 0x3f3f3f3fusing namespace std;const int MAXN=1000;int uN,vN;//u,v数目int g[MAXN][MAXN];int linker[MAXN];bool used[MAXN];bool dfs(int u)//从左边开始找增广路径{ int v; for(v=1;v<=vN;v++)//这个顶点编号从0开始,若要从1开始需要修改 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=1;u<=uN;u++) { memset(used,0,sizeof(used)); if(dfs(u))res++; } return res;}struct node1{ int xmin, xmax, ymin ,ymax;}num1[M];struct node2{ int x,y;}num2[M];int path[M];int main(){ // freopen("cin.txt","r",stdin); int n,cas=1; while(~scanf("%d",&n)&&n) { vN=uN=n; for(int i=1;i<=n;i++)scanf("%d%d%d%d",&num1[i].xmin,&num1[i].xmax,&num1[i].ymin,&num1[i].ymax); for(int i=1;i<=n;i++)scanf("%d%d",&num2[i].x,&num2[i].y); memset(g,0,sizeof(g)); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(num2[j].x<num1[i].xmax&&num2[j].x>num1[i].xmin&&num2[j].y<num1[i].ymax&&num2[j].y>num1[i].ymin) { // num[cnt].a=i;num[cnt].b=j;cnt++; g[j][i]=1; } } } int sum=hungary(); // printf("sum=%d\n",sum); bool fl=0; printf("Heap %d\n",cas++); if(sum==n) { for(int i=1;i<=n;i++)path[i]=linker[i];//保存最大情况下的匹配关系 for(int i=1;i<=n;i++) { g[path[i]][i]=0;//将这个匹配关系设成0 if(hungary()==n)continue; else { if(fl)printf(" "); printf("(%c,%d)",'A'+i-1,path[i]); fl=1; } g[path[i]][i]=1;//还原 } } if(!fl)printf("none"); puts(""); puts(""); } return 0;}
0 0
- poj1486Sorting Slides【二分图匹配判断是否是必须】
- poj1486 Sorting Slides 二分图匹配的必须边
- HDU 2444 判断是否是二分图以及二分最大匹配
- POJ1486 Sorting Slides 二分图最大匹配 必要匹配
- hdu 2444 The Accomodation of Students (判断是否是二分图,最大匹配)
- HDU 2444 The Accomodation of Students(判断是否是二分图及求最大匹配)
- POJ1486 Sorting Slides【二分匹配】
- POJ 1486 Sorting Slides 求二分图的必须边
- POJ 1486 Sorting Slides(二分图必须边)
- 判断图是否是二分图
- BFS/DFS 判断是否是二分图
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- POJ - 1486 Sorting Slides 二分图 完美匹配
- POJ1486 Sorting Slides (二分图求最大匹配)
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- poj 1486 Sorting Slides(二分图匹配必要边)
- ZOJ-1197-Sorting Slides【二分图匹配】【拓扑排序】
- POJ 1486 Sorting Slides(二分图最大匹配:关键边)
- PL/SQL 配置登陆名失败的原因
- 【操作系统】课程主页
- maven的settings.xml配置
- tomcat 访问其他目录
- 寻找测试用例以及最终的结果是修改他的数据
- poj1486Sorting Slides【二分图匹配判断是否是必须】
- 求数组中数的最大值、最小值(C语言)
- 选择排序算法
- Spark Streaming生成RDD并执行Spark Job源码内幕解密
- 一个好的微信运营胜过100个销售人员:微信运营深度剖析
- 1-14 串口在S3C2440上的原理、配置与驱动实现
- HDU 4807 Lunch Time(费用流)★
- 线性时间的哈希排序
- Java 中MD5 和SHA加密算法工具类