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. Spring5参考指南:Bean的生命周期管理

    文章目录 Spring Bean 的生命周期回调 总结生命周期机制 startup和Shutdown回调 优雅的关闭Spring IoC容器 Spring Bean 的生命周期回调 Spring中的B ...

  2. Vue.js中scoped引发的CSS作用域探讨

    前言 在Vue.js的组件化开发中,常常会对某个组件的style标签加上scoped属性,如<style lang='less' scoped>,这样做的目的在于使这个组件的样式不能轻易在 ...

  3. PHP版DES算法加密数据(3DES)另附openssl_encrypt版本

    PHP版DES算法加密数据(3DES) 可与java的DES(DESede/CBC/PKCS5Padding)加密方式兼容 <?php /** * Created by PhpStorm. * ...

  4. Algorithm Exercises

    汇总一些常见的算法题目,参考代码. 注:部分题目没有合适的oj地址 枚举 Perfect Cubes.Biorhythms.Counterfeit Dollar.EXTENDED LIGHTS OUT ...

  5. ACM-ICPC 2019 山东省省赛D Game on a Graph

    Game on a Graph Time Limit: 1 Second Memory Limit: 65536 KB There are people playing a game on a con ...

  6. java读源码 之 list源码分析(ArrayList)---JDK1.8

    java基础 之 list源码分析(ArrayList) ArrayList: 继承关系分析: public class ArrayList<E> extends AbstractList ...

  7. 一分钟html页面倒计时可精确到秒

    <!doctype html> <html> <head> <meta charset="utf-8"> </head> ...

  8. Coursera课程笔记----Write Professional Emails in English----Week 3

    Introduction and Announcement Emails (Week 3) Overview of Introduction & Announcement Emails Bas ...

  9. leetcode_雇佣 K 名工人的最低成本(优先级队列,堆排序)

    题干: 有 N 名工人. 第 i 名工人的工作质量为 quality[i] ,其最低期望工资为 wage[i] . 现在我们想雇佣 K 名工人组成一个工资组.在雇佣 一组 K 名工人时,我们必须按照下 ...

  10. 【Scala】新手入门,基础语法概览

    目录 变量.常量和数据类型 var val 数据类型 条件表达式 块表达式 to循环 for循环 for推导式 scala中的方法和函数 方法的定义 函数的定义 函数和方法的区别 变量.常量和数据类型 ...