POJ1468 Sorting Slides
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 4442 | Accepted: 1757 |
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
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
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
————————————————————————————————————
题目的意思是给出n个矩形,里面每个分配一个数字,问唯一的数字有哪几个
思路:二分图匹配关键边判定,先求二分图匹配,再枚举去掉已匹配的每一条边,判是否匹配数减少,若减少则为关键边
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
int mat[MAXN];
int aa[MAXN];
struct area
{
int x1,x2,y1,y2;
} s[100005];
struct point
{
int x,y;
} p[100005]; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
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=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int k,n;
int cas=1;
while(~scanf("%d",&n)&&n)
{
for(int i=0; i<n; i++)
scanf("%d%d%d%d",&s[i].x1,&s[i].x2,&s[i].y1,&s[i].y2);
for(int i=0; i<n; i++)
scanf("%d%d",&p[i].x,&p[i].y);
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if(p[i].x>s[j].x1&&p[i].x<s[j].x2&&p[i].y>s[j].y1&&p[i].y<s[j].y2)
g[i][j]=1;
}
uN=vN=n;
int Match=hungary();
printf("Heap %d\n",cas++); if(Match<n)
{
printf("none\n");
continue;
}
for(int i=0; i<n; i++)
mat[i]=linker[i];
int ct=0;
for(int i=0; i<n; i++)
{
g[mat[i]][i]=0;
if(hungary()<n)
{
aa[ct++]=i;
}
g[mat[i]][i]=1;
}
if(ct==0)
printf("none\n");
else
{
int q=0;
for(int i=0; i<ct; i++)
{
if(q++)
printf(" ");
printf("(%c,%d)",'A'+aa[i],mat[aa[i]]+1);
}
printf("\n");
}
printf("\n");
}
return 0;
}
POJ1468 Sorting Slides的更多相关文章
- 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: 5390 Accepted: 2095 De ...
- poj1486 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4812 Accepted: 1882 De ...
- poj 1486 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4469 Accepted: 1766 De ...
- UVA663 Sorting Slides(烦人的幻灯片)
UVA663 Sorting Slides(烦人的幻灯片) 第一次做到这么玄学的题,在<信息学奥赛一本通>拓扑排序一章找到这个习题(却发现标程都是错的),结果用二分图匹配做了出来 蒟蒻感觉 ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- poj 1486 Sorting Slides(二分图匹配的查找应用)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- Sorting Slides(二分图匹配——确定唯一匹配边)
题目描述: Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not ...
- POJ 1486 Sorting Slides(寻找必须边)
题意:找出幻灯片与编号唯一对应的情况 思路: 1:求最大匹配,若小于n,则答案为none,否则转2 (不过我代码没有事先判断一开始的最大匹配数是否<n,但这样也过了,估计给的数据最大匹配数一定为 ...
随机推荐
- Oracle_PL/SQL(6) 触发器(序列、视图)
序列1.创建序列create sequence seq_alog start with 1 increment by 1 maxvalue 999999999999999999999999999 mi ...
- Oracle_SQL(4) DDL 表和约束
数据库对象分为占存储空间的对象和不占存储存储空间的对象.占存储空间的对象主要包括:表.索引等.select distinct segment_type from dba_segments order ...
- PAT 1068 万绿丛中一点红(20)(测试点分析+思路分析)
1068 万绿丛中一点红(20 分) 对于计算机而言,颜色不过是像素点对应的一个 24 位的数值.现给定一幅分辨率为 M×N 的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的 ...
- GTK图形控件中的rc文件使用心得
转载自: 1.http://blog.csdn.net/saintwinona/article/details/6972754 2. (1).GTK 主题指南 1.Widgets GT ...
- JSP属性的四种保存范围(page request session application)
JSP提供了四种属性的保存范围,分别为page.request.session.application 其对应的类型分别为:PageContext.ServletRequest.HttpSession ...
- Spring ApplicationContext(一)初始化过程
Spring 容器 ApplicationContext(一)初始化过程 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ...
- SparkStreaming updateStateByKey 保存记录信息
)(_+_) ) 查看是否存在,如果存在直接获取 )) ssc.checkpoint() )) //使用updateStateByKey 来更新状态 val stateDstream = wordDs ...
- 比较完整的HIS系统解释(转载记录)
HIS系统即医院信息系统(全称为Hospital Information System).在国际学术界,它已被公认为是新兴的医学信息学的重要分支.HIS系统的有效运行,将提高医院各项工作的效率和质量, ...
- python学习 day3 (3月4日)---字符串
字符串: 下标(索引) 切片[起始:终止] 步长[起始:终止:1] 或者-1 从后往前 -1 -2 -3 15个专属方法: 1-6 : 格式:大小写 , 居中(6) s.capitalize() s ...
- kbmmw 的HTTPSmartService中的跨域访问
有同学在使用kbmmw 与extjs 结合的时候,涉及到了跨域访问,这个在 kbmmw 里面已经完全解决. extjs 在访问跨域的时候,首先会使用OPIONS 调用,服务端要根据浏览器请求的 he ...