当前位置:网站首页>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
边栏推荐
- Usage scenarios of golang context
- Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
- Leetcode backtracking method
- 4. Object mapping Mapster
- __ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
- Redis publish subscribe command line implementation
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
- 1.15 - input and output system
- RecyclerView的应用
猜你喜欢
1.手动创建Oracle数据库
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
Leetcode stack related
Chapter 6 relational database theory
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
MySQL advanced part 2: storage engine
Open source storage is so popular, why do we insist on self-development?
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
MySQL advanced part 1: View
MySQL advanced part 1: stored procedures and functions
随机推荐
Sqlmap tutorial (1)
Client use of Argo CD installation
1.13 - RISC/CISC
Bit of MySQL_ OR、BIT_ Count function
Leetcode-6109: number of people who know secrets
MySQL advanced part 1: index
[rust notes] 17 concurrent (Part 2)
2022/6/29-日报
Doing SQL performance optimization is really eye-catching
ollvm编译出现的问题纪录
[wustctf2020] plain_ WP
LeetCode 0107. Sequence traversal of binary tree II - another method
Records of some tools 2022
2021apmcm post game Summary - edge detection
11-gorm-v2-02-create data
在新线程中使用Handler
[leetcode] day94 reshape matrix
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
3.Oracle-控制文件的管理
MySQL advanced part 2: MySQL architecture