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相关推荐

  1. CF4D D. Mysterious Present

    做题链接: D. Mysterious Present 题目: 给出一个限制(w, h),和n个物品的二维信息(wi,hi)求物品二维都满足wi > w, hi > h的前提下的最长二维严 ...

  2. 2022.02.05 Mysterious Present神秘的礼物

    https://acs.jxnu.edu.cn/problem/CF4D 描述: Peter decided to wish happy birthday to his friend from Aus ...

  3. Codeforces Beta Round #4 (Div. 2)【完结】

    2022.3.3 题单地址:https://codeforces.com/contest/4 目录 A. Watermelon[思维] B. Before an Exam[贪心] C. Registr ...

  4. 杭电OJ分类题目(4)-Graph

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(4) HDU Graph Theory - U ...

  5. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  6. Codeforces 4D Mysterious (DP)

     Peter decided to wish happy birthday to his friend from Australia and send him a card. To make hi ...

  7. 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 ...

  8. 【ASP.NET Core】解决“The required antiforgery cookie xxx is not present”的错误

    当你在页面上用 form post 内容时,可能会遇到以下异常: The required antiforgery cookie "????????" is not present ...

  9. UserWarning: Label not :NUMBER: is present in all training examples

    UserWarning: Label not :NUMBER: is present in all training examples 目录 UserWarning: Label not :NUMBE ...

最新文章

  1. 大牛书单 | Python方向的好书
  2. 德国KubeCon直击:如何轻松且安心地将k8s用于生产?
  3. Shell脚本Ping监控主机是否存活并发邮件报警(三种方法)
  4. Django整理(二) - 视图和模板的初步使用
  5. 2519485c7dcfe0295a41d4e0f69bb10a 求解
  6. VueX的store的简单使用心结
  7. 森近林之助【字符串处理】
  8. 线程中task取消_Rust Async: async-task源码分析
  9. python伪装浏览器什么意思_python爬虫伪装浏览器出现问题求助
  10. RxJava学习(四利用RxJava打造自己的RxBus)
  11. 中国数码电影摄影机行业市场供需与战略研究报告
  12. JavaScript-数组相关作业
  13. Intellij IDEA设置系列(四):各种乱码解决方案
  14. c# 链接mongDB集群实战开发2
  15. docker 启动时错误docker: Cannot connect to the Docker daemon
  16. linux挂载,格式化
  17. 计算机的自带拍视频教程,电脑如何录制视频并剪辑
  18. 考试系统服务器 倒计时,考试系统倒计时实现
  19. 深度学习新手神器,floydhub gpu云主机!
  20. 我从小就有一个疑问,为什么所有的星球都是漂浮在空中的?

热门文章

  1. 达梦数据库项目 SpringBoot + jpa + DM8
  2. OpenStack Queens版搭建详解
  3. 浩方登录不上服务器无响应,sv独立客户端无法登陆服务器(sv独立客户端连接失败)...
  4. python 心形线_python 心形
  5. wundos无法对计算机进行启动,fanhuiwundos电脑提醒不是正版想
  6. 黑马程序员匠心之作|C++教程从0到1入门编程(60 指针-const修饰指针61 指针-指针和数组62 指针-指针和函数63 指针-指针配合数组和函数的案例)
  7. All work and no play makes jack a dull boy 中谓语为什么用makes
  8. 指纹识别系统设计(VC++)
  9. python value_counts_pandas中.value_counts()的用法
  10. 2018.07.17【省赛模拟】模拟B组 比赛题解(总结)