hdu4268
multiset中upper_bound的使用
//multiset //iterator lower_bound( const key_type &key ): 返回一个迭代器,指向键值>= key的第一个元素。 //iterator upper_bound( const key_type &key ):返回一个迭代器,指向键值> key的第一个元素。 #include<iostream> #include<cstdio> #include<set> #include<stdlib.h> using namespace std; struct NODE { int h; int w; bool type; } node[202000]; multiset<int>s; int cmp(NODE a,NODE b) { if(a.h!=b.h) return a.h<b.h; else if(a.w!=b.w) return a.w<b.w ; else return a.type>b.type ; } int main() { int T,N,num,i; scanf("%d",&T); while(T--) { scanf("%d",&N); for(i=1;i<=N;i++) { scanf("%d%d",&node[i].h,&node[i].w); node[i].type=0; } for(i=N+1;i<=2*N;i++) { scanf("%d%d",&node[i].h,&node[i].w); node[i].type=1; } sort(node+1,node+1+2*N,cmp); num=0; s.clear(); for(i=1;i<=2*N;i++) { if(node[i].type==1) s.insert(node[i].w); else { if(!s.empty()) { if(*s.begin()<=node[i].w) { multiset <int>::iterator it=s.upper_bound(node[i].w); num++; it--; s.erase(it); } } } } printf("%d\n",num); } return 0; }