{POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000
思路:O(N^2)铁定超时啊。。。。利用贪心的思想去找答案。利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的。这个题目确实不错,思路很好
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <memory>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#include <stack>
using namespace std; #define CLR(x,y) memset(x,y,sizeof(x))
#define MIN(m,v) (m)<(v)?(m):(v)
#define MAX(m,v) (m)>(v)?(m):(v)
#define ABS(x) ((x)>0?(x):-(x))
#define rep(i,x,y) for(i=x;i<y;++i) const int MAXN = 110000; int n,m;
int len;
int val;
int s[MAXN]; int BF(int cur)
{
int low,high,mid;
int pre; low = 0;
high = len-1;
while(low <= high)
{
mid = (low+high)>>1;
if(s[mid]<cur){
low = mid+1;
}
else if(s[mid]>cur){
high = mid-1;
}
else
return mid;
}
return low;
}
void Solve()
{
while(scanf("%d",&n)!=EOF)
{
len = 0;
for(int i = 0 ; i < n; ++i)
{
scanf("%d",&val);
if(len == 0 || s[len-1] < val){
s[len] = val;
++len;
}
else
{
int f = BF(val);
s[f] = val;
}
} printf("%d\n",len);
}
} int main()
{
Solve(); return 0;
}
{POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}的更多相关文章
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- POJ 3903 Stock Exchange 【最长上升子序列】模板题
<题目链接> 题目大意: 裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找. O(nlogn)算法 #i ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- POJ 3903 Stock Exchange 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
- LIS(nlogn) POJ 3903 Stock Exchange
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- poj3903 Stock Exchange(最长上升子序列)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3903">http://poj.org/problem?id=3903 Descrip ...
随机推荐
- Unable to find messages file 'cscui.dll' 问题解决
之前在工作机器上安装VS 2015卡死,结束进程,安装失败一直无法使用,昨天下班开着电脑把VS 2015卸载了,今天早上来,以前正确的项目现在生成都报错 "Unable to find me ...
- TensorFlow中max pooling层各参数的意义
官方教程中没有解释pooling层各参数的意义,找了很久终于找到,在tensorflow/python/ops/gen_nn_ops.py中有写: def _max_pool(input, ksize ...
- 如何消除移动端a标签点击时的蓝色底色以及a标签link、visited、hover、active的顺序
1.消除a标签移动端点击时的蓝色底色 -webkit-tap-highlight-color:transparent 2.link.visited.hover.active的顺序 a:link{tex ...
- 每天一个 Linux 命令(18):locate 命令
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...
- linux php bom
之前都是用cleanbom.php来去除BOM的.今天运行提示没有异常文件,但是用Fiddler还是看到了EF BB BF,删除缓存也无效,将cleanbom.php上传到生产环境也提示没有异常. 这 ...
- web app开发之rem
CSS3新增了一个相对单位rem,官方的解释为“font size of the root element”,相对于根元素(html)的font size. rem,em,px单位的区别: rem单位 ...
- spring mvc使用@InitBinder 标签对表单数据绑定
在SpringMVC中,bean中定义了Date,double等类型,如果没有做任何处理的话,日期以及double都无法绑定. 解决的办法就是使用spring mvc提供的@InitBinder标签 ...
- SpringMVC工作环境搭建 配置文件
web.xml配置 在服务器端容器启动之前加载配置文件的顺序:context-param>listener>filter>servlet //容器配置application上下文的时 ...
- vim入门过程
先下载了一本VIM的用户手册. 看到可以使用vimtutor(VIM的入门教程,很不错,由浅入深)作为入门. Unix系统中,请在命令行输入:vimtutor,进入教程. MS-Windows系统中, ...
- 【练习】数据移动---导出(EXPDP)
1.导出表: [oracle@host03 datadump]$ expdp scott/tiger directory=dir_dp dumpfile=emp.dmp tables=emp; Exp ...