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,但这样也过了,估计给的数据最大匹配数一定为 ...
随机推荐
- python程序设计——面向对象程序设计:方法
类中定义的方法分为四类:公有方法,私有方法,静态方法,类方法 公有方法.私有方法都属于对象,私有方法的名字以"__"开始 每个对象都有自己的公有方法和私有方法,这两类方法可以访问属 ...
- 数据库mysql的常规操作
1. 什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的建立在计算机存储设备上的仓库. 简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进 ...
- Amazon Seller Central is Temporarily Unavailable
Seller Central is Temporarily Unavailable We apologize for the inconvenience. Our technical staff is ...
- 深入react技术栈解读
1. react实现virtual DOM ,如果要改变页面的内容,还是需要执行DOM操作,比原生操作DOM多了virtualDOM的操作(计算,对比等), 应该是更耗性能??? 2. react特点 ...
- ES6的新特性(1)——ES6 的概述
ES6 的概述 首先,感谢马伦老师的ES6新特性的教程. ECMAScript 和 JavaScript 的关系是 ECMAScript 和 JavaScript 的关系是,前者是后者的规格,后者是前 ...
- AppCan 之初体验
平台概述 什么是AppCan 移步这里,楼主的一句话:可以匹敌 Phonegap .Titanium .Sencha Touch .MUI .ImagApp.Nitrous .apicloud .起步 ...
- 只执行一次的js 函数。
function runOnce(fn, context) { //控制让函数只触发一次 return function () { try { fn.apply(context || this, ar ...
- webpack入门指南-step01
一.webpack是什么? web开发中常用到的静态资源主要有JavaScript.CSS.图片.Jade等文件,webpack中将静态资源文件称之为模块.webpack是一个模块打包工具(命令行工具 ...
- Saver 保存与读取
tensorflow 框架下的Saver 功能,用以保存和读取运算数据 Saver 保存数据 代码 import tensorflow as tf # Save to file #remember t ...
- lintcode-81-数据流中位数
81-数据流中位数 数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 说明 中位数的定义: 中位数是排序后数组的中间值,如果有数组中有n个数,则中位数为A[(n-1)/ ...