分类:思维
题目链接:Uva11134-Fabled Rooks
那个定义运算符<的地方,如果改成这样就错了,不知道神马原因
bool operator < (const node &rhs) const
{
if (l != rhs.l) return l > rhs.l ;
return r > rhs.r ;
}
先按行放,再看看列满不满足即可
#include<bits/stdc++.h>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const ll maxn=5000+500;
struct node
{
int l,r,id;
friend bool operator < (node a,node b)
{
if (a.l != b.l) return a.l > b.l ;
return a.r > b.r ;
}
}a[maxn],b[maxn];
int n;
int ans[maxn][2];
bool work(node *a,int pos)
{
priority_queue<node> Q;
for (int i=0 ;i<n ;i++) Q.push(a[i]);
while(!Q.empty())
{
node temp=Q.top();
Q.pop();
}
for (int i=0 ;i<n ;i++) Q.push(a[i]);
int loc=0;
while (!Q.empty())
{
node temp=Q.top() ;Q.pop() ;
if (temp.r<loc) return false;
if (temp.l<loc)
{
temp.l=loc;
Q.push(temp);
continue;
}
loc=temp.l;
ans[temp.id][pos]=loc;
loc++;
}
return true;
}
int main()
{
while (scanf("%d",&n)!=EOF && n)
{
for (int i=0 ;i<n ;i++)
{
scanf("%d%d%d%d",&a[i].l,&b[i].l,&a[i].r,&b[i].r);
a[i].id=b[i].id=i;
}
if (work(a,0) && work(b,1))
{
for (int i=0 ;i<n ;i++)
printf("%d %d\n",ans[i][0],ans[i][1]);
}
else printf("IMPOSSIBLE \n");
}
return 0;
}