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,但这样也过了,估计给的数据最大匹配数一定为 ...
随机推荐
- Cuteftp连接虚拟机Centos7
使用Centos7虚拟机时,想要从主机传一些文件到虚拟机,需要使用FTP传输,在主机上装上的CuteFTP的软件,对虚拟机进行配置. 1,首先,要保证虚拟机能够上网 一般装好虚拟机后,只要主机连了网, ...
- Selenium WebDriver 下 plugin container for firefox has stopped working
用selenium 的webdriver 和 firefox 浏览器做自动化测试,经常会出现 plugin container for firefox has stopped working 如下图所 ...
- eclipse安装反编译器jad
1.下载net.sf.jadclipse_3.3.0.jar.jadclipse_3.3.0.jar.jad.exe 2.将net.sf.jadclipse_3.3.0.jar放在eclipse的安装 ...
- 爬虫:Scrapy12 - Stats Collection
Scrapy 提供了方便的收集数据的机制.数据以 key/value 方式存储,值大多是计数值.该机制叫做数据收集器(Stats Collector),可以通过 Crawler API 的属性 sta ...
- OpenCV学习笔记——疑问
vec3b:表示每一个Vec3b对象中,可以存储3个char(字符型)数据,比如可以用这样的对象,去存储RGB图像中的一个像素点.typedef Vec<uchar, 3> Vec3b; ...
- 福大软工1816 ·软工之404NoteFound团队选题报告
目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...
- Floyd算法(原理|代码实现)
http://www.cnblogs.com/twjcnblog/archive/2011/09/07/2170306.html 正如我们所知道的,Floyd算法用于求最短路径.Floyd算法可以说是 ...
- 今目标登录时报网络错误E110
今目标登录的时候报错了,错误代码:E110不论怎么修改都修复不了,百度相关资料也没有,只能联系客服. 经过好久终于联系上了客服,客服给出的解决方案是修改:Enternet选项: 第一步:打开,控制面板 ...
- C++ Primer Plus学习:第十三章
第十三章 类继承 继承的基本概念 类继承是指从已有的类派生出新的类.例: 表 0-1 player.h class player { private: string firstname; string ...
- MySQL 备份和恢复 理论知识
为什么要备份 数据无价 制定备份策略的注意点 1:可容忍丢失多少数据 2:恢复需要在多长时间内完成 3:备份的对象 数据.二进制日志和InnoDB的事务日志.SQL代码(存储过 ...