Sorting Slides
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4777   Accepted: 1867

Description

Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he is not a very tidy person and has put all his transparencies on one big heap. Before giving the talk, he has to sort the slides. Being a kind of minimalist, he wants to do this with the minimum amount of work possible.

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

The input consists of several heap descriptions. Each heap descriptions starts with a line containing a single integer n, the number of slides in the heap. The following n lines contain four integers xmin, xmax, ymin and ymax, each, the bounding coordinates 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

For each heap description in the input first output its number. Then print a series of all the slides whose numbers can be uniquely determined from the input. Order the pairs by their letter identifier.

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 贪心WA 二分又WA一次 5
1 4 1 4
2 7 2 7
5 11 5 11
8 13 9 14
9 14 8 13
3 3
3 3
6 6
10 10
12 12 结果应该是(C,3),但贪心的结果是none
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int used[N],x[N],y[N];
bool vis[N],mp[N][N];
vector<int>G[N];
struct node
{
int xi,xx,yi,yx;
} e[N];
struct point
{
int x,y;
bool operator < (const point &A)const
{
return x<A.x;
}
} al[N];
bool findx(int x)
{
for(int i=; i<(int)G[x].size(); ++i)
{
int v=G[x][i];
if(vis[v]||mp[x][v]) continue;
vis[v]=;
if(!used[v]||findx(used[v]))
{
used[v]=x;
return true;
}
}
return false;
}
int ctx[N],cty[N];
int main()
{
int n,tas=;
while(scanf("%d",&n),n)
{
for(int i=; i<=n; ++i) G[i].clear();
for(int i=; i<=n; ++i) scanf("%d%d%d%d",&e[i].xi,&e[i].xx,&e[i].yi,&e[i].yx);
for(int i=; i<=n; ++i) scanf("%d%d",&x[i],&y[i]);
for(int i=; i<=n; ++i) for(int j=; j<=n; ++j) if(e[i].xi<=x[j]&&x[j]<=e[i].xx&&e[i].yi<=y[j]&&e[i].yx>=y[j]) G[i].push_back(j);
memset(used,,sizeof(used));
memset(mp,,sizeof(mp));
int tot=,maxmatch=,fx=;
for(int i=; i<=n; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++maxmatch;
}
for(int i=; i<=n; ++i) if(used[i]) ctx[tot]=used[i],cty[tot++]=i;
printf("Heap %d\n",tas++);
if(!tot) puts("none");
else
{
/*for(int i=0; i<tot; ++i)
            {
                mp[ctx[i]][cty[i]]=1;
                memset(vis,0,sizeof(vis));
                used[cty[i]]=0;
                if(!findx(ctx[i])) al[fx].x=ctx[i],al[fx++].y=cty[i];
                mp[ctx[i]][cty[i]]=0;
                used[cty[i]]=ctx[i];
            }这么写不对的*/
for(int i=; i<tot; ++i)
{
int now=;
mp[ctx[i]][cty[i]]=;
memset(used,,sizeof(used));
for(int i=; i<=n; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++now;
}
if(now!=maxmatch) al[fx].x=ctx[i],al[fx++].y=cty[i];
mp[ctx[i]][cty[i]]=;
}
if(!fx) puts("none");
else
{
sort(al,al+fx);
for(int i=; i<fx; ++i) printf("(%c,%d) ",al[i].x+'A'-,al[i].y);
puts("");
}
}
puts("");
}
}

poj1486二分匹配 待填坑的更多相关文章

  1. Cython的用法以及填坑姿势

    因为项目需要,需要优化已有的Python代码.目前Python代码的执行过程是将Python代码转变成一行行指令,然后解释器解释指令的执行,调用到C代码层.如果去掉指令解释这个阶段,直接进入C代码层, ...

  2. Android项目开发填坑记-Fragment的onBackPressed

    Github版 CSDN版 知识背景 Fragment在当前的Android开发中,有两种引用方式,一个是 Android 3.0 时加入的,一个是supportV4包中的.这里简称为Fragment ...

  3. Android Studio 3.0正式版填坑之路

    原文:https://www.jianshu.com/p/9b25087a5d7d   Android Studio 3.0启动图 序言 总看别人的文章,今天尝试着自己来写一篇.在逛论坛时候,无意间发 ...

  4. Vue2.0 新手完全填坑攻略——从环境搭建到发布

    Jinkey原创感谢 showonne.yubang 技术指导Demo 地址:http://demo.jinkey.io/vue2源码:https://github.com/Jinkeycode/vu ...

  5. 动归专题QAQ(两天创造的刷题记录哟!✿✿ヽ(°▽°)ノ✿✿)(未填坑)

    1092 采药:由于没有限制开始时间和结束时间,01背包就好了 1095 开心的金明:01背包,无fuck说 1104 摆花:f[i][j]表示摆了i种花,第i种花摆了j种的方案数,乱转移0.0(感觉 ...

  6. [react-native]react-native填坑笔记

    填坑笔记 开始入坑RN,从最开始的学起难免有不少乱七八糟的问题,记录在这里. 1. 8081端口占用问题 按照官网教程搭建开发环境并按照下面代码运行时候有报错,显示8081端口的问题 react-na ...

  7. hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. Vue3+Typescript+Node.js实现微信端公众号H5支付(JSAPI v3)教程--各种填坑

    ----微信支付文档,不得不说,挺乱!(吐槽截止) 功能背景 微信公众号中,点击菜单或者扫码,打开公众号中的H5页面,进行支付. 一.技术栈 前端:Vue:3.0.0,typescript:3.9.3 ...

  9. Android—基于微信开放平台v3SDK,开发微信支付填坑。

    接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...

随机推荐

  1. 浅析Java三大特性封装、继承、多态,及作业分析

    前言 本次博客衔接上次博客,作为这一阶段Java学习的分析.上一篇博客着重介绍了Java的OO编程思维,面向对象与面向过程的区别.本篇博客重心在Java的三大技术特性,附带作业分析. Java三大特性 ...

  2. tr标签使用hover的box-shadow效果不生效

    先说问题: 这是大致的HTML结构 <table cellpadding="0" cellspacing="0"> <thead> &l ...

  3. #if 和#ifdef的区别

    转自:https://blog.csdn.net/zhangchiytu/article/details/7563329 先看个例子:#define TARGET_LITTLE_ENDINA 1#de ...

  4. 解决vue中BMap未定义问题

    原文链接: 点我 最近在项目中使用了百度地图来显示物流信息,实现方式有两种: 引用Vue Baidu Map引用BMap存在的问题:\color{red}{存在的问题:}存在的问题::使用BMap可以 ...

  5. C++编程入门题目--No.4

    题目: 输入某年某月某日,判断这一天是这一年的第几天? 程序分析: 以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天. #incl ...

  6. 多线程高并发编程(7) -- Future源码分析

    一.概念 A Future计算的结果. 提供方法来检查计算是否完成,等待其完成,并检索计算结果. 结果只能在计算完成后使用方法get进行检索,如有必要,阻塞,直到准备就绪. 取消由cancel方法执行 ...

  7. UIResponder相关

    UIResponder是OC中一个响应事件的类.UIApplication.UIView.UIViewController都是它的子类.UIWindow是UIView的子类,因此也能响应事件. UIR ...

  8. Spring Cloud 学习 之 Spring Cloud Bus实现修改远程仓库后配置自动刷新

    ​ 版本号: ​ Spring Boot:2.1.3.RELEASE ​ Spring Cloud:G版 ​ 开发工具:IDEA 搭建配置中心,这里我们搭建一个简单版的就行 POM: <?xml ...

  9. 将csv文件导入sql数据库

    有一个csv文件需要导入到Sql数据库中,其格式为 “adb”,"dds","sdf" “adb”,"dds","sdf" ...

  10. 解密C语言编译背后的过程

    我们大部分程序员可能都是从C语言学起的,写过几万行.几十万行.甚至上百万行的代码,但是大家是否都清楚C语言编译的完整过程呢,如果不清楚的话,我今天就带着大家一起来做个解密吧. C语言相对于汇编语言是一 ...