hdu 4585 set应用

时间:2022-06-20 01:13:29
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#define Maxn 100010
using namespace std;
struct Monk{
int id,g;
int operator <(const Monk &temp) const
{
return g<temp.g;
}
};
multiset<Monk> q;
multiset<Monk> :: iterator it,it1;
int main()
{
int n,i,j,g,k,x;
Monk temp;
while(scanf("%d",&n),n)
{
q.clear();
temp.id=,temp.g=;
q.insert(temp);
for(i=;i<=n;i++)
{
scanf("%d%d",&k,&g);
temp.id=k,temp.g=g;
it=q.lower_bound(temp);
if(it==q.begin())
{
printf("%d %d\n",k,it->id);
}
else{
it1=it;
it--;
if(it1->g-g<g-it->g)
{
printf("%d %d\n",k,it1->id);
}
else
{
printf("%d %d\n",k,it->id);
}
}
q.insert(temp);
}
}
return ;
}