poj 1486 Sorting Slides(二分图匹配的查找应用)
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 , B has number , C number and A number . 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 , the next pair for , etc. No number will lie on a slide boundary. The input is terminated by a heap description starting with n = , 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
Sample Output
Heap
(A,) (B,) (C,) (D,) Heap
none
Source
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100
int n;
int x1[N],x2[N],y1[N],y2[N];
int mp[N][N];
int match[N];
int path[N];
int vis[N];
bool dfs(int x){
for(int i=;i<n;i++){
if(!vis[i] && mp[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
int solve(){
int ans=;
memset(match,-,sizeof(match)); for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
}
return ans;
}
int main()
{
int ac=;
while(scanf("%d",&n)== && n){
printf("Heap %d\n",++ac);
for(int i=;i<n;i++){
scanf("%d%d%d%d",&x1[i],&x2[i],&y1[i],&y2[i]);
}
memset(mp,,sizeof(mp));
for(int i=;i<n;i++){
int a,b;
scanf("%d%d",&a,&b);
for(int j=;j<n;j++){
if(a>x1[j] && a<x2[j] && b>y1[j] && b<y2[j]){
mp[i][j]=;
}
}
} int ans=solve();
//printf("===%d\n",ans);
int flag=;
if(ans==n){
for(int i=;i<n;i++){
path[i]=match[i];
}
for(int i=;i<n;i++){
int u=path[i];
mp[u][i]=;//这个表示匹配的每一条边?
if(solve()==n) continue;
else{
if(flag)
printf(" ");
printf("(%c,%d)",'A'+i,path[i]+);
flag=;
}
mp[u][i]=; }
}
if(!flag){
printf("none");
}
printf("\n\n"); }
return ;
}
poj 1486 Sorting Slides(二分图匹配的查找应用)的更多相关文章
- POJ 1486 Sorting Slides (二分图关键匹配边)
题意 给你n个幻灯片,每个幻灯片有个数字编号1~n,现在给每个幻灯片用A~Z进行编号,在该幻灯片范围内的数字都可能是该幻灯片的数字编号.问有多少个幻灯片的数字和字母确定的. 思路 确定幻灯片的数字就是 ...
- POJ 1486 Sorting Slides(二分图完全匹配必须边)题解
题意:给你n张照片的范围,n个点的坐标,问你能唯一确定那几个点属于那几张照片,例如样例中4唯一属于A,2唯一属于C,1唯一属于B,3唯一属于C 思路:进行二分图完全匹配,怎么判断唯一属于?匹配完之后删 ...
- POJ 1486 Sorting Slides (KM)
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2831 Accepted: 1076 De ...
- poj 1486 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4469 Accepted: 1766 De ...
- POJ 1486 Sorting Slides(二分图匹配)
[题目链接] http://poj.org/problem?id=1486 [题目大意] 给出每张幻灯片的上下左右坐标,每张幻灯片的页码一定标在这张幻灯片上, 现在问你有没有办法唯一鉴别出一些幻灯片 ...
- POJ 1486 Sorting Slides【二分图匹配】
题目大意:有n张幻灯片和n个数字,幻灯片放置有重叠,每个数字隶属于一个幻灯片,现在问你能够确定多少数字一定属于某个幻灯片 思路:上次刷过二分图的必须点后这题思路就显然了 做一次二分匹配后将当前匹配的边 ...
- POJ 1486 Sorting Slides(寻找必须边)
题意:找出幻灯片与编号唯一对应的情况 思路: 1:求最大匹配,若小于n,则答案为none,否则转2 (不过我代码没有事先判断一开始的最大匹配数是否<n,但这样也过了,估计给的数据最大匹配数一定为 ...
- POJ 3057 Evacuation(二分图匹配+BFS)
[题目链接] http://poj.org/problem?id=3057 [题目大意] 给出一个迷宫,D表示门,.表示人,X表示不可通行, 每个门每时间单位只允许一个人通过, 每个人移动一格的为一时 ...
- POJ 3041 Asteroids (二分图匹配)
[题目链接] http://poj.org/problem?id=3041 [题目大意] 一个棋盘上放着一些棋子 每次操作可以拿走一行上所有的棋子或者一列上所有的棋子 问几次操作可以拿完所有的棋子 [ ...
随机推荐
- 解决html5新标签【placeholder】低版本浏览器下不兼容问题
placeholder属性是HTML5 中为input添加的.在input上提供一个占位符,文字形式展示输入字段预期值的提示信息(hint),该字段会在输入为空时显示. 实例:1 <input ...
- ajax弹出窗口
提取自ZCMS的弹出框: 代替window.open.window.alert.window.confirm:提供良好的用户体验: 水晶质感,设计细腻,外观漂亮: 兼容ie6/7/8.firefox2 ...
- Hadoop 类Grep源代码注释
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agree ...
- 3:url无规律的多页面爬取
试例网站:豆瓣电影TOP250:http://movie.douban.com/top250 关键点:在审查元素下查看后页即可以看到跳转的url.而且最后一页就此属性就没有了. 由于关键是实现分页,所 ...
- 手动向IIS注册.net框架组件
安装.NET Framework时,会自动在IIS上注册ASP.NET,如果已经存在.NET Framework再安装的IIS,必须告诉IIS已经存在framework. 有时IIS功能缺失或异常 ...
- Linux 开机报 or type Control-D to continue
解决步骤: 1.输入root密码 2.看是哪个盘报的错,我这边是sda3(可能会是不同的盘),就是代码中标为FAIL 输入以下命令fsck -y /dev/sda3
- Xcode7国际化(根据系统语言切换App显示的语言) - 元宵节快乐!
老规矩, 上gif 下面是配置的大概流程: 这个是要显示中文的.strings文件的内容和格式 这个是要显示英文的.strings文件的内容和格式 下面是应用名部分: 然后下面是代码部分: impor ...
- 启动外部exe程序
Process myProcess = new Process();myProcess.StartInfo.FileName = pathName;myProcess.Start();其中的pathN ...
- java下tcp的socket连接案例
package cn.stat.p4.ipdemo; import java.io.BufferedReader; import java.io.IOException; import java.io ...
- 12个用得着的JQuery代码片段
1. 导航菜单背景切换效果 在项目的前端页面里,相对于其它的导航菜单,激活的导航菜单需要设置不同的背景.这种效果实现的方式有很多种,下面是使用JQuery实现的一种方式: <ul id='nav ...