路径:906. 区间分组 - AcWing题库
思路:
可以想到是求区间最厚的地方。
每次输入l,r区间让l*2,r*2+1存入同一个数组;
注意:当l=r时,要先计算左点。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
using namespace std;
#define LL long long
const int N = 2e5+100;
int b[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int l, r;
cin >> l >> r;
b[2 * i - 1] = l * 2;
b[2 * i] = r * 2+1;
}
n =n*2;
sort(b + 1, b + 1 + n);
int ans = 0,maxx=0;
for (int i = 1; i <= n; i++)
{
if (b[i] % 2 == 0) ans++;
else ans--;
maxx = max(ans, maxx);
}
cout << maxx << endl;
return 0;
}