当前位置:网站首页>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 
边栏推荐
- MySQL advanced part 2: the use of indexes
- Leetcode-3: Longest substring without repeated characters
- Basic explanation of typescript
- Leetcode dynamic programming
- 论文阅读报告
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- [rust notes] 14 set (Part 1)
- 1.14 - assembly line
- Leetcode recursion
- [2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
猜你喜欢

International Open Source firmware Foundation (osff) organization

Open source storage is so popular, why do we insist on self-development?

Bit of MySQL_ OR、BIT_ Count function

Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging

Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams

博弈论 AcWing 894. 拆分-Nim游戏

Client use of Argo CD installation

Day 2 document

栈 AcWing 3302. 表达式求值

什么是套接字?Socket基本介绍
随机推荐
求组合数 AcWing 887. 求组合数 III
4. 对象映射 - Mapping.Mapster
Leetcode-1200: minimum absolute difference
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
What's wrong with this paragraph that doesn't work? (unresolved)
Leetcode divide and conquer / dichotomy
2048项目实现
RecyclerView的应用
2048 project realization
[BMZCTF-pwn] ectf-2014 seddit
Leetcode-3: Longest substring without repeated characters
Real time clock (RTC)
MySQL advanced part 1: stored procedures and functions
Shutter web hardware keyboard monitoring
Presentation of attribute value of an item
阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
FFmpeg build下载(包含old version)
Redis publish subscribe command line implementation
3.Oracle-控制文件的管理
Winter vacation water test 1 Summary