#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. UML——综合实例

  2. Yii zii.widgets.grid 隐藏列 方便js获取隐藏值

    array( 'name' => $data->is_audit, 'value' => '$data->is_audit', 'headerHtmlOptions' => ...

  3. Cocos2d-x数据持久化-查询数据

    数据查询一般会带有查询条件,这可以使用SQL语句的where子句实现,但是在程序中需要动态绑定参数给where子句.查询数据的具体操作步骤如下所示.(1) 使用sqlite3_open函数打开数据库. ...

  4. IOS 解析JSON

    - (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view, t ...

  5. krpano资料

  6. Android应用资源--之属性(Attribute)资源

    原文链接: http://wujiandong.iteye.com/blog/1184921 属性(Attribute)资源:属于整个Android应用资源的一部分.其实就是网上一堆介绍怎么给自定义V ...

  7. Java 对于继承的初级理解

    概念:继承,是指一个类的定义可以基于另外一个已存在的类,即子类继承父类,从而实现父类的代码的重用.两个类的关系:父类一般具有各个子类共性的特征,而子类可以增加一些更具个性的方法.类的继承具有传递性,即 ...

  8. c#基础学习汇总----------base和this,new和virtual

    base和this是c#中的两访问关键字,目的是用于实现继承机制的访问操作,来满足对对象成员的访问,从而为多态机制提供更加灵活的处理方式. 在看<你必须知道的.Net>一书中有一个例子很好 ...

  9. UVaLive 3708

    题意:周长为10000的圆上等距分布n个雕塑,求再加入m个雕塑后,为使所有雕塑等距分布所需移动原来n个雕塑的最小总距离. 分析:计算相对距离. #include<cstdio> #incl ...

  10. 坑爹系列:sizeof运算符

    C语言里的sizeof关键字用于返回变量的类型宽度(变量所占的字节个数).例如: #include <stdio.h> int main() { int i = 0; int size = ...