hdu 4585 set应用
#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=1,temp.g=1000000000; q.insert(temp); for(i=1;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 0; }