本文共 1320 字,大约阅读时间需要 4 分钟。
http://acm.hust.edu.cn/vjudge/contest/123100#problem/B
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define mem(a,b) memset(a,b,sizeof(a))#define pf printf#define sf scanf#define spf sprintf#define pb push_back#define debug printf("!\n")#define MAXN 100000 + 10#define MAX(a,b) a>b?a:b#define blank pf("\n")#define LL long long#define ALL(x) x.begin(),x.end()#define INS(x) inserter(x,x.begin())#define pqueue priority_queue#define INF 0x3f3f3f3fint n,m;struct node{ int h,w;}a[200005],b[200005];bool cmp(node x,node y){ return x.h < y.h;}multiset mt;multiset ::iterator it;int main(){ int i,j; int t; sf("%d",&t); while(t--) { sf("%d",&n); for(i=1;i<=n;i++) { sf("%d%d",&a[i].h,&a[i].w); } for(i=1;i<=n;i++) { sf("%d%d",&b[i].h,&b[i].w); } sort(a+1,a+n+1,cmp); sort(b+1,b+n+1,cmp); mt.clear(); int cnt=0; for(i=1,j=1;i<=n;i++) { while(j<=n && a[i].h>=b[j].h) { mt.insert(b[j].w); j++; } if(mt.empty()) continue; it = mt.upper_bound(a[i].w); if(it!=mt.begin()) it--; if((*it) <= a[i].w) { cnt++; mt.erase(it); } } pf("%d\n",cnt); } return 0;}
转载于:https://www.cnblogs.com/qlky/p/5693459.html