906. 区间分组(贪心)

路径: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 bN;

int main() {

int n;

cin >> n;

for (int i = 1; i <= n; i++)

{

int l, r;

cin >> l >> r;

b2 \* i - 1 = l * 2;

b2 \* 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 (bi % 2 == 0) ans++;

else ans--;

maxx = max(ans, maxx);

}

cout << maxx << endl;

return 0;

}

相关推荐
Shadow(⊙o⊙)16 分钟前
专题六:模拟算法
算法
小飞在努力11 小时前
【实现负载均匀在线判题③】从零散模块到统一,编译运行全链路封装
c语言·开发语言·c++·笔记
民乐团扒谱机15 小时前
【超详细】基频音高提取算法之SWIPE 算法深度解析:频谱匹配的精度极限与工程边界
人工智能·算法
饮水桶_T15 小时前
C++ stack & queue复习笔记
开发语言·笔记·算法
星恒随风15 小时前
从0实现C++ AI大模型接入SDK(四):大模型API接入、公共数据结构设计与日志库封装
linux·服务器·数据结构·c++·人工智能
炸膛坦客15 小时前
单片机/C/C++八股:(三十四)C 语言函数参数入栈顺序
c语言·开发语言·c++
wy_hhxx16 小时前
[Leetcode] 滑动窗口
算法·leetcode·滑动窗口
码途行者16 小时前
每天10分钟学Go:第20课 泛型
c++·算法·golang
AIgorithmGEEK18 小时前
算法·哈希表|从“逐个比”到“按 key 算位置”
数据结构·c++·算法·leetcode·hash