当前位置:网站首页>【集训DAY3】 Section【贪心】【二分】
【集训DAY3】 Section【贪心】【二分】
2022-07-15 18:16:00 【VL——MOESR】

思路:
先把左端点排序,然后右端点做最长不上升子序列
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;
}
边栏推荐
- MySQL reports an error mysqld:sort aborted:server shutdown in progress reason
- Provide/Inject
- 事件4624是登录成功!?!真的如此吗?
- Refute 'all management without assessment is nonsense'
- @Repository @ [email protected] Understanding of annotations
- 利用蜜罐反制蓝队
- 微信小程序激活账号时,提示“此帐号已激活,请使用帐号密码直接登录”
- Unity2D--相机跟随
- PolarDB for PostgreSQL的HTAP跨机并行查询的执行方法是什么?
- Go1.18升级功能 - 模糊测试Fuzz | 从零开始Go语言
猜你喜欢

Qt(二)UI控件简介与 可选树状控件演示

90% of people have never used Microsoft!

Qt(四)使用代码与UI文件混合开发

Torch in pytoch numel(),torch. shape,torch. Size () and torch Reshape() function parsing

第四讲:最长上升子串

【每日一题】558. 四叉树交集

微信小程序激活账号时,提示“此帐号已激活,请使用帐号密码直接登录”

MySQL 关于 zip安装包 的安装过程

Connecting with enterprise wechat, customer relationship management can also be very simple!

测试光流传感器速度特性
随机推荐
EasyGBS平台编辑设备管理分组时,出现崩溃该如何解决?
【Luogu_P5431】【模板】乘法逆元 2【数论】
Torch in pytoch numel(),torch. shape,torch. Size () and torch Reshape() function parsing
How to add PTZ control to the easycvr video retrieval page?
Range of motion of leecode robot
数据库:使用WHERE语句进行检索(头歌)
SAP ABAP 系统进行数据库表查询的几种常用方法
Yesdev: easily collaborate on every project
How can home building materials enterprises build a smart supply chain management system? Digital commerce cloud supply chain system focuses on multi business application scenarios of procurement and
A-F codeworks round 806 (div.4) A-F problem solution and code
In the throes of household appliance market transformation, SaaS system platform is applied to inject new momentum into the development of household appliance industry
VxWorks环境搭建与学习
pytorch替换numpy中的一些组件 //转载请注明来源
About March 2022, apt-c-41 disguised as winrar Exe attack terminal side emergency response troubleshooting point
Da Vinci pro's FPGA learning notes 6.2 -- VCs and Verdi development hummingbird e203
R语言使用reshape2包的melt函数进行dataframe变形将dataframe数据从宽表变换为长表、dcast函数把melt函数处理后的数据、基于一个自定义公式(formula)从长表到宽表
傅立叶变换的物理意义
Daily question 1: the minimum value of the sum of the largest number pairs in the array (leecode)
当使用single-branch clone仓库后,如何添加跟踪的远程分支?
Unity2D--相机跟随