uva 11143
#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的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- 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 ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 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 ...
随机推荐
- asp.net php asp jsp 301重定向的代码
介绍一下针对各类程序系统实施301重定向的代码: 1.Linux主机重定向 Godaddy的Liunx主机,Godaddy本身已经支持Apache,所以直接创建一个.htaccess文件就可以了,一般 ...
- Xcode 真机无法调试
关于只能在模拟器上测试不能在真机测试的问题 2. 在 buildSetting 里面搜索bitcode,更改为 No 即可.
- Json文件/网址解析
// // main.m // OC8-Json文件解析 // // Created by qianfeng on 15/6/23. // Copyright (c) 2015年 qianfeng. ...
- OC7_复合类内存管理(setter方法)
// // Person.h // OC7_复合类内存管理(setter方法) // // Created by zhangxueming on 15/6/18. // Copyright (c) 2 ...
- css笔记——css 实现自定义按钮
css实现自定义按钮的样式实际上很早就有了,只是会用的人不是很多,里面涉及到了最基础的css写法,在火狐中按钮还是会显示出来,这时需要将i标签的背景设置为白色,同时z-index设置比input高一些 ...
- SpringMVC中注解和非注解方式下的映射器和适配器总结
1. 非注解方式 1.1 处理器适配器 上一节中使用的处理器适配器是:org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapte ...
- [zz] 使用ssh公钥密钥自动登陆linux服务器
目录 .生成密匙对 .拷贝公匙到远程机 .启动登陆代理 这种方法处理后每次需要运行命令:ssh-add ~/.ssh/id_dsa 作为一名 linux 管理员,在多台 Linux 服务器上登陆进行远 ...
- 第一个C++
输入:cin>>(相当于scanf) #include <iostream> using namespace std; int main() { int number; ...
- GridView - javascript 触发后台 OnSelectedIndexChanged
1.ASPX <asp:GridView ID="gdvDealers" runat="server" AutoGenerateColumns=" ...
- Spark Streaming揭秘 Day26 JobGenerator源码图解
Spark Streaming揭秘 Day26 JobGenerator源码图解 今天主要解析一下JobGenerator,它相当于一个转换器,和机器学习的pipeline比较类似,因为最终运行在Sp ...