# UVA11134_Fabled Rooks

xy互相并不干扰,所以就可以把这个二维问题压缩成一维的,即在x轴能否让第i个点落在第i个区间内,如果x或y轴不存在这样放法,那么二维肯定也不可以!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 1e5+100;
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<endl;
typedef long long ll;
bool vis[maxn];
int n;
struct node
{
int l,r,num;
node():l(0),r(0),num(0){}
bool operator < (const node& rhs)const
{
return r < rhs.r || (r == rhs.r && l < rhs.l);
}
}x[maxn],y[maxn];
bool slove(int* a,node* q)
{
memset(a, 0, sizeof a);
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; ++i)
{
for(int j = q[i].l; j <= q[i].r; ++j)
{
if(!vis[j])
{
a[q[i].num] = j;
vis[j] = 1;
break;
}
if(j == q[i].r)
{
// pr(q[i].num);pr(q[i].l);prln(q[i].r);
return false;
}
}
}
return true;
}
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int a[maxn],b[maxn];
while(cin >> n && n)
{
for(int i = 0; i < n; ++i)
{
scanf("%d%d%d%d",&x[i].l,&y[i].l,&x[i].r,&y[i].r);
x[i].num = y[i].num = i;
}
sort(x, x + n);sort(y, y + n);
if(slove(a,x)&&slove(b,y))
{
for(int i = 0; i < n; ++i)
printf("%d %d\n",a[i], b[i]);
}
else
{
printf("IMPOSSIBLE\n");
}
}
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120