#include <iostream> #include <map> #include <cstdio> #include <cmath> using namespace std; //key:实力值power value:id号 int main(){ map<int,int> members; members[1000000000] = 1; int n,id,power; scanf("%d",&n); map<int,int>::iterator it,pre,next; while(n --){ scanf("%d%d",&id,&power); members[power] = id; it = pre = next = members.find(power); pre --; next ++; if(it == members.begin()) printf("%d %d\n",id,next -> second); else if(next == members.end()) printf("%d %d\n",id,pre -> second); else if(abs(it -> first - pre -> first) > abs(it -> first - next -> first)) printf("%d %d\n",id,next -> second); else printf("%d %d\n",id,pre -> second); } return 0; }
标签:pre,map,power,42,next,second,members,id From: https://www.cnblogs.com/balabalabubalabala/p/16919708.html