标签:
题意:
map的这种用法还没见过呢,下次重拍一遍
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string> 10 #include <math.h> 11 #include <stdlib.h> 12 using namespace std; 13 14 int main() 15 { 16 map<int,int>mp; 17 int n; 18 while(scanf("%d",&n) == 1 && n) 19 { 20 mp.clear(); 21 mp[1000000000] = 1; 22 int u,v; 23 while(n--) 24 { 25 scanf("%d%d",&u,&v); 26 printf("%d ",u); 27 map<int,int>::iterator it = mp.lower_bound(v); 28 if(it == mp.end()) 29 { 30 it--; 31 printf("%d\n",it->second); 32 } 33 else 34 { 35 int t1 = it->first; 36 int tmp = it->second; 37 if(it != mp.begin()) 38 { 39 it--; 40 if(v - it->first <= t1 - v) 41 { 42 printf("%d\n",it->second); 43 } 44 else printf("%d\n",tmp); 45 } 46 else printf("%d\n",it->second); 47 } 48 mp[v] = u; 49 } 50 } 51 return 0; 52 }
标签:
原文地址:http://www.cnblogs.com/cnblogs321114287/p/4624861.html