poj1486 Sorting Slides
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4812 | Accepted: 1882 |
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
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,a[][],pipei[],flag[],can[][],cnt,ans[][],cas;
int pipei2[];
bool print = false;
struct node
{
int minx,maxx,miny,maxy;
} e[];
struct node2
{
int x,y;
} point[]; bool dfs(int u)
{
for (int i = ; i <= n; i++)
if (a[u][i] && !flag[i])
{
flag[i] = ;
if (!pipei[i] || dfs(pipei[i]))
{
pipei[i] = u;
return true;
}
}
return false;
} bool dfs2(int u)
{
for (int i = ; i <= n; i++)
if (a[u][i] && !flag[i])
{
flag[i] = ;
if (!pipei2[i] || dfs2(pipei2[i]))
{
pipei2[i] = u;
return true;
}
}
return false;
} int main()
{
while (scanf("%d",&n) && n)
{
memset(pipei,,sizeof(pipei));
memset(can,,sizeof(can));
memset(ans,,sizeof(ans));
memset(a,,sizeof(a));
cnt = ;
print = false;
for (int i = ; i <= n; i++)
scanf("%d%d%d%d",&e[i].minx,&e[i].maxx,&e[i].miny,&e[i].maxy);
for (int i = ; i <= n; i++)
scanf("%d%d",&point[i].x,&point[i].y);
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
if (point[j].x >= e[i].minx && point[j].x <= e[i].maxx && point[j].y >= e[i].miny && point[j].y <= e[i].maxy)
a[j][i] = ;
for (int i = ; i <= n; i++)
{
memset(flag,,sizeof(flag));
if (dfs(i))
cnt++;
}
for (int i = ; i <= n; i++)
{
a[pipei[i]][i] = ;
int cnt2 = ;
memset(pipei2,,sizeof(pipei2));
for (int j = ; j <= n; j++)
{
memset(flag,,sizeof(flag));
if(dfs2(j))
cnt2++;
}
if (cnt2 < cnt)
ans[i][pipei[i]] = ;
a[pipei[i]][i] = ;
}
printf("Heap %d\n",++cas);
for (int i = ; i <= n; i++)
if (ans[i][pipei[i]])
{
print = true;
printf("(%c,%d) ",'A' + i - ,pipei[i]);
}
if (!print)
printf("none");
printf("\n\n");
} return ;
}
poj1486 Sorting Slides的更多相关文章
- POJ1468 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4442 Accepted: 1757 De ...
- 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 ...
- 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,但这样也过了,估计给的数据最大匹配数一定为 ...
随机推荐
- sqli-labs学习笔记 DAY3
DAY 3 sqli-labs lesson 6 同lesson 5,只是把单引号改为双引号 sqli-labs lesson 7 同lesson 5,只是把单引号后面加两个空格,使用Burpsuit ...
- 华为笔试——C++特定位数比较
题目:特定位数比较 题目介绍:输入两行数据,第一行为 m 个正整数,以空格隔开:第二行为正整数 n ,且 n<= m:要求对第一行的数字的后三位大小进行排序,输出排行 n 的数字,其中,若不满三 ...
- 当Kubernets遇上阿里云 -之七层负载均衡(一).
我们知道Kubernetes的service只能实现基于4层的负载均衡,无法提供7层之上的许多特性,诸如基于URL的负载均衡,SSL支持,三方授权等等:Ingress可以实现七层负载均衡的许多功能,唯 ...
- ViewPort <meta>标记
ViewPort <meta>标记用于指定用户是否可以缩放Web页面,如果可以,那么缩放到的最大和最小缩放比例是什么.使用ViewPort <meta>标记还表示文档针对移动设 ...
- scrum立会报告+燃尽图(第三周第七次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2286 项目地址:https://coding.net/u/wuyy694 ...
- 04慕课网《进击Node.js基础(一)》HTTP讲解
HTTP:通信协议 流程概述: http客户端发起请求,创建端口默认8080 http服务器在端口监听客户端请求 http服务器向客户端返回状态和内容 稍微详细解析: 1.域名解析:浏览器搜素自身的D ...
- .net组件和com组件&托管代码和非托管代码
com组件和.net组件: COM组件是非托管对象,可以不需要.NET框架而直接运行,.NET框架组件是托管对象,必须有.NET框架的支撑才能运行. COM组件有独立的类型库文件,而.NET组件是通过 ...
- 线段树---成段更新hdu1698 Just a Hook
hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...
- C语言之goto浅析
1. 读代码时遇了的疑惑点: static int do_bind(const char *host, int port, int protocol, int *family) { int fd; ...
- Spring中jdbc Template使用
http://1358440610-qq-com.iteye.com/blog/1826816