HDU4329
#include<cstdio> #include<algorithm> #include<map> using namespace std; int main() { map<int ,int>mp; int n; while(~scanf("%d",&n)&&n) { int id,fg; mp[1000000000]=1; for(int i=0; i<n; i++) { scanf("%d %d",&id,&fg); mp[fg]=id; map<int ,int>::iterator it=mp.find(fg),it1; if(it==mp.begin()) printf("%d %d\n",id,(++it)->second); else { it1=it; if(abs((--it)->first-fg)<=abs((++it1)->first-fg)) printf("%d %d\n",id,(it)->second); else printf("%d %d\n",id,(it1)->second); } } mp.clear(); } return 0; }
map是有序的好处