当前位置:网站首页>[training day3] section [greed] [two points]
[training day3] section [greed] [two points]
2022-07-27 13:57:00 【VL——MOESR】

Ideas :
Sort the left endpoint first , Then do the longest Non rising subsequence at the right endpoint
c o d e code code
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 10;
int n, tot, b[MAXN];
struct node {
int x, y;
}a[MAXN];
bool cmp(node x, node y) {
if(x.x!=y.x) return x.x < y.x;
else return x.y > y.y;
}
int Find(int x) {
int l=1, r=tot, ans = 1e9;
while(l <= r) {
int mid = l + r >> 1;
if(b[mid] < x) r = mid - 1, ans = min(ans, mid);
else l = mid + 1;
}
return ans;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a+1, a+1+n, cmp);
tot = 1, b[1] = a[1].y;
for(int i = 2; i <= n; i ++) {
if(a[i].y <= b[tot]) b[++tot] = a[i].y;
else {
int k = Find(a[i].y);
b[k] = a[i].y;
}
}
printf("%d", tot);
return 0;
}
边栏推荐
- Recommended collection, confusing knowledge points of PMP challenge (2)
- Database kernel developer, worth a mug!!!
- Echart line chart displays the last point and vertical dotted line by default
- 基于C语言实现线性表的建立、插入、删除、查找等基本操作
- Wechat campus laundry applet graduation design finished product (6) opening defense ppt
- The salary level of programmers in various countries is a little miserable
- Motion attitude control system of DOF pan tilt based on stm32
- Jianzhi offer 07 rebuild binary tree -- construct binary tree from middle order and post order traversal sequence
- Construction and application of industrial knowledge atlas (I): overview of industrial knowledge atlas
- 纯c手写线程池
猜你喜欢

利用C语言实现URL解析的基本方法之优秀

【idea】设置提取serialVersionUID

Redis cluster setup - use docker to quickly build a test redis cluster

for .. of可用于哪些数据的遍历

《C语言》函数栈帧的创建与销毁--(内功)

Recommended collection, confusing knowledge points of PMP challenge (2)

Design of network abnormal traffic analysis system

Wechat campus laundry applet graduation design finished product of applet completion work (3) background function

Converter registration of easyexcel

不需要标注数据的语义分割!ETH&鲁汶大学提出MaskDistill,用Transformer来进行无监督语义分割,SOTA!...
随机推荐
NoSQL —— NoSQL 三大理论基石 —— CAP —— BASE—— 最终一致性
【idea】设置提取serialVersionUID
Keras深度学习实战——推荐系统数据编码
Data enhancement in image processing
Experience sharing of system architecture designers preparing for the exam: a tough battle for nearly three months
Huiliang technology app is a good place to go to sea: after more than ten years of popularity, why should the United States still choose to go to sea for gold
【LeetCode】592. 分数加减运算
Come and watch, 17 practical skills of operation and maintenance~
js回调函数(callback)
Software testing system architecture designer concise tutorial | software testing
Use recyclerview to realize the left sliding menu of the list
Various ways to use new
Egg swagger doc graphic verification code solution
【图论】负环
Thinkphp+ pagoda operation environment realizes scheduled tasks
基于C语言实现线性表的建立、插入、删除、查找等基本操作
Leetcode Tencent selected exercises 50 questions -059. Spiral matrix II
在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
深度置信网络(DBN)【经典的DBN网络结构是由若干层 RBM(受限波尔兹曼机)和一层 BP 组成的一种深层神经网络】
小程序毕设作品之微信校园洗衣小程序毕业设计成品(5)任务书