题意:
思路:
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<vector> #include<queue> #include<stack> #include<map> #include<algorithm> using namespace std; map<int,int> a; const int INF=1000000000; int main() { int n; while(scanf("%d",&n) && n) { a.clear(); a[INF]=1; for(int i=0;i<n;i++) { int id,x; scanf("%d %d",&id,&x); printf("%d ",id); map<int,int>::iterator index=a.lower_bound(x); int res1=index->first; int res2=index->second; if(index!=a.begin()) { index--; if(x-index->first <= res1-x) printf("%d ",index->second); else printf("%d ",res2); } else printf("%d ",res2); a[x]=id; } } return 0; }