[CF4D]Mysterious Present
4D:Mysterious Present
题意简述
给出一个限制 >(w,h) >(w,h)和 n n个物品的二维信息(xi,yi)(x_i,y_i)。
求物品二维都满足限制的前提下,最长严格上升子序列 xi>xi−1,yi>yi−1 x_i>x_{i-1},y_i>y_{i-1}。
数据范围
1≤n≤ 5000 1 \leq n \leq 5000
1≤w,h≤106 1 \leq w,h \leq 10^6
1≤xi,yi≤106 1 \leq x_i,y_i \leq 10^6
思路
按照一维排序,第二维就是一个LIS。
注意二分的时候是lower_bound等于的也要包括。
时间复杂度 O(nlogn) O(nlogn)
代码
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct data{int x,y;int id;bool operator < (const data &n1) const{return x==n1.x ? y>n1.y :x<n1.x;}
}d[5010];
int n,w,h,t,tail;
int g[5010],pre[5010];
int in()
{char ch=getchar();while (ch<'0'||ch>'9')ch=getchar();int ret=0;while (ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();return ret;
}
bool cmp(const int &a,const int &b)
{return d[a].y<d[b].y;
}
int dfs(int x)
{if (pre[x])dfs(pre[x]);printf("%d ",x);
}
int main()
{n=in(),w=in(),h=in();for (int i=1;i<=n;i++)d[i].x=in(),d[i].y=in(),d[i].id=i;sort(d+1,d+n+1);g[tail++]=0;for (int i=1;i<=n;i++){if (d[i].x<=w||d[i].y<=h)continue;if (d[i].y>d[g[tail-1]].y){g[tail++]=i;pre[d[i].id]=d[g[tail-2]].id;}else{t=lower_bound(g,g+tail,i,cmp)-g;g[t]=i;pre[d[i].id]=d[g[t-1]].id;}}printf("%d\n",tail-1);if (tail>1)dfs(d[g[tail-1]].id);return 0;
}
[CF4D]Mysterious Present相关推荐
- CF4D D. Mysterious Present
做题链接: D. Mysterious Present 题目: 给出一个限制(w, h),和n个物品的二维信息(wi,hi)求物品二维都满足wi > w, hi > h的前提下的最长二维严 ...
- 2022.02.05 Mysterious Present神秘的礼物
https://acs.jxnu.edu.cn/problem/CF4D 描述: Peter decided to wish happy birthday to his friend from Aus ...
- Codeforces Beta Round #4 (Div. 2)【完结】
2022.3.3 题单地址:https://codeforces.com/contest/4 目录 A. Watermelon[思维] B. Before an Exam[贪心] C. Registr ...
- 杭电OJ分类题目(4)-Graph
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(4) HDU Graph Theory - U ...
- ACM比赛经验、刷题记录及模板库总结(更新中)
前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...
- Codeforces 4D Mysterious (DP)
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make hi ...
- CentOS Linux解决 Device eth0 does not seem to be present
通过OVF部署Linux主机后提示 ringing up interface eth0: Device eth0 does not seem to be present,delaying initi ...
- 【ASP.NET Core】解决“The required antiforgery cookie xxx is not present”的错误
当你在页面上用 form post 内容时,可能会遇到以下异常: The required antiforgery cookie "????????" is not present ...
- UserWarning: Label not :NUMBER: is present in all training examples
UserWarning: Label not :NUMBER: is present in all training examples 目录 UserWarning: Label not :NUMBE ...
最新文章
- 大牛书单 | Python方向的好书
- 德国KubeCon直击:如何轻松且安心地将k8s用于生产?
- Shell脚本Ping监控主机是否存活并发邮件报警(三种方法)
- Django整理(二) - 视图和模板的初步使用
- 2519485c7dcfe0295a41d4e0f69bb10a 求解
- VueX的store的简单使用心结
- 森近林之助【字符串处理】
- 线程中task取消_Rust Async: async-task源码分析
- python伪装浏览器什么意思_python爬虫伪装浏览器出现问题求助
- RxJava学习(四利用RxJava打造自己的RxBus)
- 中国数码电影摄影机行业市场供需与战略研究报告
- JavaScript-数组相关作业
- Intellij IDEA设置系列(四):各种乱码解决方案
- c# 链接mongDB集群实战开发2
- docker 启动时错误docker: Cannot connect to the Docker daemon
- linux挂载,格式化
- 计算机的自带拍视频教程,电脑如何录制视频并剪辑
- 考试系统服务器 倒计时,考试系统倒计时实现
- 深度学习新手神器,floydhub gpu云主机!
- 我从小就有一个疑问,为什么所有的星球都是漂浮在空中的?
热门文章
- 达梦数据库项目 SpringBoot + jpa + DM8
- OpenStack Queens版搭建详解
- 浩方登录不上服务器无响应,sv独立客户端无法登陆服务器(sv独立客户端连接失败)...
- python 心形线_python 心形
- wundos无法对计算机进行启动,fanhuiwundos电脑提醒不是正版想
- 黑马程序员匠心之作|C++教程从0到1入门编程(60 指针-const修饰指针61 指针-指针和数组62 指针-指针和函数63 指针-指针配合数组和函数的案例)
- All work and no play makes jack a dull boy 中谓语为什么用makes
- 指纹识别系统设计(VC++)
- python value_counts_pandas中.value_counts()的用法
- 2018.07.17【省赛模拟】模拟B组 比赛题解(总结)