这道题首先要知道可以讲横纵坐标分开讨论。
这样就转化为区间贪心的问题。
要注意的是要用并查集优化一下。
对左端点排序,然后从右端点找到第一个没有被使用的点。
假设i点的根节点为x,并且x在区间内,就合并:pre[x] = find(x+1)。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e3+5;
int Case = 1;
int n, m;
struct node{
int l, r, id;
bool operator<(const node x)const{
return r < x.r;
}
}A[maxn], B[maxn];
int res[maxn][2];
int pre[maxn];
int find(int x) {
int t = x;
while(pre[t