HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列+n*logn算法)
来源:互联网 发布:学淘宝开店的书籍 编辑:程序博客网 时间:2024/05/16 08:12
要求没有两根线交叉的最多道路,因为每个p只对应于一个r.所以只要满足是上升序列,其线段一定不会交叉。
以前只会O(n^2)算法,这道题目测会跪,研究了网上的解题报告,又涨姿势了-_-#
dp[i]存储长度为i的序列末尾元素的最小值。关键在于二分查找。
#include <cstdio>#include <iostream>using namespace std;const int maxn =500000+5;int f[maxn],dp[maxn];int main(){ int n,len,T=0; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++){ int x,y; scanf("%d%d",&x,&y); f[x]=y; } dp[1]=f[1];len=1; for(int i=2;i<=n;i++) { int low=1,up=len; while(low<=up) { int mid=(low+up)>>1; if(f[i]>dp[mid]) low=mid+1; else up=mid-1; } dp[low]=f[i];//找到的是大于等于f[i]的第一个位置 if(low>len) len++; } printf("Case %d:\n",++T); if(len==1) printf("My king, at most 1 road can be built.\n\n"); else printf("My king, at most %d roads can be built.\n\n",len); } return 0;}
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列+n*logn算法)
- hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升序列n*logn算法)
- HDU 1025.Constructing Roads In JGShining's Kingdom【最长上升子序列n×logn算法】【1月6】
- 最长上升子序列 nlogn算法 hdu 1025 Constructing Roads In JGShining's Kingdom
- hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列nlogn算法)
- hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列的o(nlog(n))算法)
- Constructing Roads In JGShining's Kingdom(最长上升子序列)
- hdu 1025 Constructing Roads In JGShining's Kingdom【即求最长上升子序列】
- hdu 1025 Constructing Roads In JGShining's Kingdom(树状数组求最长上升子序列)
- hdu 1025 Constructing Roads In JGShining's Kingdom (最长上升子序列)
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列(nlogn)
- HDU-1025 Constructing Roads In JGShining's Kingdom O(nlogn)的最长上升子序列
- hdu 1025 Constructing Roads In JGShining's Kingdom(二分法+最长上升子序列)
- 【DP】HDU 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列
- HDU 1025 —— Constructing Roads In JGShining's Kingdom 最长上升子序列
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP,LIS最长上升子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom(LIS最长上升子序列)
- 公司办公网络arp木马防治方案20120519
- 视频编码的常见参数基本概念
- 时间转化成数字
- Socket编程指南及示例程序
- PDFiend
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列+n*logn算法)
- 文件操作
- Hosts文件介绍:工作方式和作用及其实践
- 虚拟地址 线性地址 物理地址
- nginx负载均衡session共享解决方案
- 介绍各种压缩格式MPEG1--MPEG4--MPEG7—MPEG21-H.264
- 实现多个文件上传
- HDR阴影高光图像增强
- icinga 添加http service