当前位置:网站首页>区间问题 AcWing 906. 区间分组
区间问题 AcWing 906. 区间分组
2022-07-27 10:35:00 【T_Y_F666】
区间问题 AcWing 906. 区间分组
原题链接
算法标签
贪心
思路
ans 最小组数, 即正确答案
cnt 按照如下算法所得合法方案
故ans<=cnt
证明ans>=cnt
所以 ans==cnt
代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 100005;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
struct Sec{
int l, r;
}sec[N];
int mxr[N];
bool cmp(Sec A, Sec B){
return A.l<B.l;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
rep(i, 0, n){
sec[i].l=read(), sec[i].r=read();
}
sort(sec, sec+n,cmp);
// 小根堆维护所有区间右端点最大值 int 区间下标 vector<int> 区间右端点
priority_queue<int, vector<int>, greater<int>> heap;
rep(i, 0, n){
// 需要开辟新区间
if(heap.empty()||heap.top()>=sec[i].l){
heap.push(sec[i].r);
}else{ // 更新当前区间右端点最大值
heap.pop();
heap.push(sec[i].r);
}
}
printf("%lld", heap.size());
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 学习笔记-minio
- Learning notes - wechat payment
- 最长上升子序列模型 AcWing 272. 最长公共上升子序列
- Overview of data security in fog computing
- Kangaroo cloud stack based on CBO in spark SQL optimization
- Overview of radar communication integrated waveform design
- Substr and substring function usage in SQL
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- antd中table hover上去的背景色样式修改
- Synaesthesia integrated de cellular super large-scale MIMO and high-frequency wireless access technology
猜你喜欢

Use of pyquery

How to assemble a registry

The difference of iteration number and information entropy

最长上升子序列模型 AcWing 1012. 友好城市

最长上升子序列模型 AcWing 482. 合唱队形

涌现与形态的局部差异和整体差异

黑白像素分布对迭代次数的影响

Derivation of the detailed expansion sto overlap integrals

pyquery 的使用

What is the mystery of the gate of the meta universe?
随机推荐
Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)
[QNX hypervisor 2.2 user manual]9.9 logger
Redis high availability principle
349两个数组的交集和01两数之和
Learning notes - simple server implementation
How to build a real-time development platform to deeply release the value of enterprise real-time data?
Use of beautifulsoup
Self optimization of wireless cell load balancing based on machine learning technology
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
迭代次数的差异与信息熵
antd table中排序th阻止悬停变色+table悬停行变色+table表头变色
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
Object array de duplication
tensorflow运行报错解决方法
Today's code farmer girl summarized her notes about NPM package management and URL module
MySQL installation (RPM package)
十年架构五年生活-07 年轻气盛的蜕变
img src为空或者src不存在,图片出现白色边框