当前位置:网站首页>Interval problem acwing 906 Interval grouping
Interval problem acwing 906 Interval grouping
2022-07-05 06:24:00 【T_ Y_ F666】
Interval problem AcWing 906. Interval grouping
Original link
Algorithm tags
greedy
Ideas
ans Minimum number of groups , The correct answer
cnt The legal scheme is obtained according to the following algorithm
so ans<=cnt
prove ans>=cnt
therefore ans==cnt
Code
#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);
// The small root heap maintains the maximum value of the right endpoint of all intervals int Interval subscript vector<int> The right end of the interval
priority_queue<int, vector<int>, greater<int>> heap;
rep(i, 0, n){
// Need to open up new areas
if(heap.empty()||heap.top()>=sec[i].l){
heap.push(sec[i].r);
}else{ // Update the maximum value of the right endpoint of the current interval
heap.pop();
heap.push(sec[i].r);
}
}
printf("%lld", heap.size());
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- RecyclerView的应用
- __ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
- 背包问题 AcWing 9. 分组背包问题
- [leetcode] day95 effective Sudoku & matrix zeroing
- 快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
- [rust notes] 14 set (Part 1)
- 20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
- Redis publish subscribe command line implementation
- Leetcode heap correlation
- Record the process of configuring nccl and horovod in these two days (original)
猜你喜欢

Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software

P2575 master fight

4. Object mapping Mapster
![[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis](/img/20/826cc9d514496955a557439881234d.jpg)
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis

区间问题 AcWing 906. 区间分组

1.14 - assembly line

3. Oracle control file management
![[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian](/img/f1/e7a8a1a31bc5712d9f32d91305a2b0.jpg)
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian

Leetcode array operation

MySQL advanced part 2: MySQL architecture
随机推荐
2048项目实现
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
2022-5-第四周日报
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
LeetCode-61
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
2048 project realization
How to generate an image from text on fly at runtime
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
Leetcode-556: the next larger element III
中国剩余定理 AcWing 204. 表达整数的奇怪方式
FFmpeg build下载(包含old version)
Winter messenger 2
C Primer Plus Chapter 15 (bit operation)
Filter the numbers and pick out even numbers from several numbers
[rust notes] 15 string and text (Part 1)
Currently clicked button and current mouse coordinates in QT judgment interface
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
New title of module a of "PanYun Cup" secondary vocational network security skills competition