#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 5100
#include<queue>
using namespace std; struct node
{
int x,y;
int id;
bool operator<(const node &t)const
{
return y>t.y;
}
} hang[maxn],lie[maxn]; bool cmp(const node &a,const node &b)
{
return a.x<b.x;
} int h[maxn],l[maxn]; priority_queue<node>q; int main()
{
int n;
while(scanf("%d",&n)&&n)
{
for(int i=; i<n; i++)
{
scanf("%d%d%d%d",&hang[i].x,&lie[i].x,&hang[i].y,&lie[i].y);
hang[i].id=lie[i].id=i;
h[i]=;
l[i]=;
}
sort(hang,hang+n,cmp);
int cur=;
int timer=;
bool flag=;
while(!q.empty())q.pop();
while()
{
while(cur<n&&hang[cur].x<=timer)q.push(hang[cur++]);
if(timer<=n&&q.empty())
{
flag=;
break;
}
node v=q.top();
q.pop();
if(timer<v.x||timer>v.y)
{
flag=;
break;
}
h[v.id]=timer;
timer++;
if(timer>n)break;
}
if(flag)
{
sort(lie,lie+n,cmp);
cur=;
timer=;
while(!q.empty())q.pop();
while()
{
while(cur<n&&lie[cur].x<=timer)q.push(lie[cur++]);
if(timer<=n&&q.empty())
{
flag=;
break;
}
node v=q.top();
q.pop();
if(timer<v.x||timer>v.y)
{
flag=;
break;
}
l[v.id]=timer;
timer++;
if(timer>n)break;
}
}
for(int i=;i<n;i++)
if(l[i]==||h[i]==)
{
flag=;
break;
}
if(flag)
{
for(int i=; i<n; i++)
printf("%d %d\n",h[i],l[i]);
}
else puts("IMPOSSIBLE");
}
return ;
}

uva 11143的更多相关文章

  1. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  2. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  3. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  4. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  5. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  6. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

  7. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

  8. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  9. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

随机推荐

  1. 程序生成SiteMapPath文件

    //创建站点地图 private void CreateSiteMap(DataSet ds) { XmlDeclaration declareation; declareation = xmlDoc ...

  2. JSP之初识2

    <与%之间不可有空格,但是后面可以有空格 <%@ page language="java" import="java.util.*" pageEnc ...

  3. 关于JAVA System常见类的一些总结

    一.JAVA System类概述 1.概述: System 类是一个抽象类,所有的字段和方法都是静态的,即不能被实例化.其中包含一些有用的类字段和方法,它不能被实例化.在 System 类提供的设施中 ...

  4. 博客迁到CSDN

    之前一直是博客园和CSDN博客同步更新 现在不在博客园继续写博客,十一国庆节假后只用CSDN博客了.祝各位访客国庆节快乐! CSDN博客地址: http://blog.csdn.net/it_liuc ...

  5. js画了一个椭圆

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. css3学习笔记之边框

    CSS3 圆角 border-radius 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <!DOCTYPE html> <h ...

  7. 关于arcgis发布wfs问题

    博客地址http://www.cnblogs.com/shizhongtao/p/3453594.html 官方文档中有这么一段描述: 从地图创建 WFS 服务 您 可以从 ArcMap 地图文档 ( ...

  8. 广度优先算法BFS

    package myalgorithm; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; / ...

  9. 在.NET连接MySQL以及封装好的MySQLHelper.cs

    1.首先上MySQL网站下驱动:http://www.mysql.com/products/connector/ 2.安装下载的安装包 3.我们在Visual Studio里创建一个Web Appli ...

  10. DTCMS自定义标签:获取所有栏目以及不显示指定栏目

    DTcms.Web.UI\Label\category.cs中 添加下面代码 /// <summary> /// 返回所有类别 /// </summary> /// <r ...