当前位置:网站首页>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
边栏推荐
- [2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
- Doing SQL performance optimization is really eye-catching
- Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
- Groupbykey() and reducebykey() and combinebykey() in spark
- Applicable to Net free barcode API [off] - free barcode API for NET [closed]
- 求组合数 AcWing 887. 求组合数 III
- 1.13 - RISC/CISC
- Is it impossible for lamda to wake up?
- Client use of Argo CD installation
- Bit of MySQL_ OR、BIT_ Count function
猜你喜欢
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
求组合数 AcWing 887. 求组合数 III
Leetcode array operation
SQL三种连接:内连接、外连接、交叉连接
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
4. 对象映射 - Mapping.Mapster
阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
SPI details
区间问题 AcWing 906. 区间分组
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
随机推荐
Sqlmap tutorial (II) practical skills I
Filter the numbers and pick out even numbers from several numbers
中国剩余定理 AcWing 204. 表达整数的奇怪方式
MySQL advanced part 1: stored procedures and functions
3. Oracle control file management
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
背包问题 AcWing 9. 分组背包问题
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
Leetcode-22: bracket generation
Open source storage is so popular, why do we insist on self-development?
求组合数 AcWing 888. 求组合数 IV
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
Day 2 document
2022/6/29-日报
[moviepy] unable to find a solution for exe
博弈论 AcWing 893. 集合-Nim游戏
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
RecyclerView的应用
Leetcode-1200: minimum absolute difference