【POJ】1486:Sorting Slides【二分图关键边判定】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5390 | Accepted: 2095 |
Description
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
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
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
Source
Solution
题意就是找所有可以唯一对应起来的矩形和数字。
看起来这种对应关系很像二分图匹配??
建成二分图后就变成判定哪些边是必须的了。必须的意思是删掉这条边最大匹配数会变小,所以对所有边删边后做一次最大匹配,与最初始的最大匹配数进行比较即可。
Code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; int n, vis[], to[], pi[];
int xi[], xa[], yi[], ya[]; bool check(int x, int y, int i) {
if(x >= xi[i] && x <= xa[i] && y >= yi[i] && y <= ya[i]) return ;
return ;
} int G[][]; bool dfs(int u) {
for(int v = ; v <= n; v ++) {
if(G[u][v]) {
if(!vis[v]) {
vis[v] = ;
if(!pi[v] || dfs(pi[v])) {
pi[v] = u;
to[u] = v;
return ;
}
}
}
}
return ;
} int match() {
memset(to, , sizeof(to));
memset(pi, , sizeof(pi));
int ans = ;
for(int i = ; i <= n; i ++) {
if(!to[i]) {
memset(vis, , sizeof(vis));
ans += dfs(i);
}
}
return ans;
} int main() {
int ti = ;
while(~scanf("%d", &n)) {
if(n == ) break;
memset(G, , sizeof(G));
for(int i = ; i <= n; i ++)
scanf("%d%d%d%d", &xi[i], &xa[i], &yi[i], &ya[i]);
for(int i = ; i <= n; i ++) {
int x, y;
scanf("%d%d", &x, &y);
for(int j = ; j <= n; j ++) {
if(!check(x, y, j)) continue;
G[j][i] = ;
}
}
int ma = match(); int flag = ;
printf("Heap %d\n", ++ ti);
for(int i = ; i <= n; i ++) {
for(int j = ; j <= n; j ++)
if(G[i][j]) {
G[i][j] = ;
if(match() < ma) {
printf("(%c,%d) ", i + , j);
flag = ;
}
G[i][j] = ;
}
}
if(!flag) printf("none\n\n");
else printf("\n\n");
}
return ;
}
【POJ】1486:Sorting Slides【二分图关键边判定】的更多相关文章
- POJ 1486 Sorting Slides (二分图关键匹配边)
题意 给你n个幻灯片,每个幻灯片有个数字编号1~n,现在给每个幻灯片用A~Z进行编号,在该幻灯片范围内的数字都可能是该幻灯片的数字编号.问有多少个幻灯片的数字和字母确定的. 思路 确定幻灯片的数字就是 ...
- poj 1486 Sorting Slides(二分图匹配的查找应用)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- 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个点的坐标,问你能唯一确定那几个点属于那几张照片,例如样例中4唯一属于A,2唯一属于C,1唯一属于B,3唯一属于C 思路:进行二分图完全匹配,怎么判断唯一属于?匹配完之后删 ...
- POJ 1486 Sorting Slides【二分图匹配】
题目大意:有n张幻灯片和n个数字,幻灯片放置有重叠,每个数字隶属于一个幻灯片,现在问你能够确定多少数字一定属于某个幻灯片 思路:上次刷过二分图的必须点后这题思路就显然了 做一次二分匹配后将当前匹配的边 ...
- POJ 1486 Sorting Slides(寻找必须边)
题意:找出幻灯片与编号唯一对应的情况 思路: 1:求最大匹配,若小于n,则答案为none,否则转2 (不过我代码没有事先判断一开始的最大匹配数是否<n,但这样也过了,估计给的数据最大匹配数一定为 ...
- POJ1468 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4442 Accepted: 1757 De ...
随机推荐
- SolrJ查询条件组合查询实现——(十六)
带查询条件的实现原理: 查询按钮被包在一个大表单,表单还有三个隐藏域,一个商品筛选,一个 价格,一个排序,每次点击查询时候清空三个隐藏域,就带着一个大条件去查询;点击下面的筛选条件时,给隐藏域的筛选条 ...
- python面向对象——类
from:http://www.runoob.com/python3/python3-class.html Python3 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在P ...
- Ubuntu使用apt-get upgrade升级时出错
今天在按照常规的sudo apt-get update更新软件列表后,再使用sudo apt-get upgrade升级软件时,出现了以下的错误: 正在设置 linux-image-extra-4.4 ...
- fcntl函数的用法总结
fcntl系统调用可以用来对已打开的文件描述符进行各种控制操作以改变已打开文件的的各种属性 函数原型: #include<unistd.h> #include<fcntl.h&g ...
- js实现数据视图双向绑定原理
这个方法了不起啊..vue.js和avalon.js 都是通过它实现双向绑定的..而且Object.observe也被草案发起人撤回了..所以defineProperty更有必要了解一下了几行代码看他 ...
- ExtJs对js基本语法扩展支持
ExtJs对js基本语法扩展支持 本篇主要介绍一下ExtJs对JS基本语法的扩展支持,包括动态加载.类的封装等. 一.动态引用加载 ExtJs有庞大的类型库,很多类可能在当前的页面根本不会用到,我们可 ...
- 在VS中让一个JS文件智能提示另一个JS文件中的成员2--具体引用
我们知道,在html中,利用<script language="javascript" type="text/javascript" src=" ...
- java基础66 JavaScript中的事件、localtion对象、screen对象(网页知识)
1.JavaScript中的事件注册 1.1.事件的注册方式 方式1:直接在html元素上注册 <body onLoad="ready()"></body > ...
- pom.xml一个简单配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- C++之构造函数的继承
#include<iostream> usingnamespace std; classBase1 { public: Base1()=default; Base1(const strin ...