对于 A中的 每一个扑克牌 在 x 可以覆盖的 范围内。 应该保证 被覆盖的 y尽量大。 这样 才是不浪费 y的。 并且 能够保证 后面的 A的 x更大的时候
出现 y 很小的时候 可以 覆盖 那些 x 小 并且 y 相对较小的。 这个思想很好的。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long LL;
typedef unsigned long long LLU;
const double PI=acos(-1.0);
using namespace std;
#define MAXN 100000+10
struct card{
int x,y;
friend bool operator < (card a, card b){
if(a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
};
card a[MAXN],b[MAXN];
int main (){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d%d",&a[i].x, &a[i].y);
for(int i = 0; i < n; i++)
scanf("%d%d",&b[i].x, &b[i].y);
sort(a,a+n);
sort(b,b+n);
multiset <int> s;
int p = 0;
int ans = 0;
for(int i = 0; i < n; i++){
while(p < n && b[p].x <= a[i].x){
s.insert(b[p].y);
p++;
}
if(s.size() >= 1){
multiset <int> ::iterator it = s.lower_bound(a[i].y);
if(it == s.end())
it--;
if(it != s.begin() && (*it) > a[i].y){
it--;
}
if((*it) <= a[i].y){
s.erase(it);
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}

851

被折叠的 条评论
为什么被折叠?



