POJ 3903 Stock Exchange

时间:2022-12-19 07:58:02
Stock Exchange
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2954   Accepted: 1082

Description

The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for rising trends. Given a sequence of numbers p1, p2,...,pn representing stock prices, a rising trend is a subsequence pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. John’s problem is to find very quickly the longest rising trend.

Input

Each data set in the file stands for a particular set of stock prices. A data set starts with the length L (L ≤ 100000) of the sequence of numbers, followed by the numbers (a number fits a long integer). 
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.

Output

The program prints the length of the longest rising trend. 
For each set of data the program prints the result to the standard output from the beginning of a line.

Sample Input

6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1

Sample Output

3
1
1
题目大意:最长上升子序列。
解题方法:这题由于数据较大,不能采用常规的DP方法来解答,那样时间复杂度为O(n^2),应采用二分,时间复杂度为n * logn。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; int main()
{
int n, low, mid, high, nLen;
int num[];
int Stack[];
while(scanf("%d", &n) != EOF)
{
nLen = ;
Stack[] = -;
for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
}
for (int i = ; i <= n; i++)
{
if (num[i] > Stack[nLen])
{
Stack[++nLen] = num[i];
}
else
{
low = ;
high = nLen;
while(low <= high)
{
mid = (low + high) / ;
if (Stack[mid] < num[i])
{
low = mid + ;
}
else
{
high = mid - ;
}
}
Stack[low] = num[i];
}
}
printf("%d\n", nLen);
}
return ;
}

POJ 3903 Stock Exchange的更多相关文章

  1. POJ 3903 Stock Exchange (E - LIS 最长上升子序列)

    POJ 3903    Stock Exchange  (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...

  2. POJ - 3903 Stock Exchange(LIS最长上升子序列问题)

    E - LIS Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Descripti ...

  3. Poj 3903 Stock Exchange(LIS)

    一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...

  4. POJ 3903 Stock Exchange 最长上升子序列入门题

    题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...

  5. &lbrace;POJ&rcub;&lbrace;3903&rcub;&lbrace;Stock Exchange&rcub;&lbrace;nlogn 最长上升子序列&rcub;

    题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...

  6. LIS&lpar;nlogn&rpar; POJ 3903 Stock Exchange

    题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...

  7. poj 3903 Stock Exchange(最长上升子序列,模版题)

    题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...

  8. POJ 3903 Stock Exchange 【最长上升子序列】模板题

    <题目链接> 题目大意: 裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找. O(nlogn)算法 #i ...

  9. POJ 3903 Stock Exchange(LIS &vert;&vert; 线段树)题解

    题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚 ...

随机推荐

  1. C&num;语言基础——集合(ArrayList集合)

    集合及特殊集合 集合的基本信息: System.Collections 命名空间包含接口和类,这些接口和类定义各种对象(如列表.队列.位数组.哈希表和字典)的集合.System.Collections ...

  2. 【android-tips】如何在view中取得activity对象

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 今天想实现在view中返回上一个activity的功能,想了半天.因为在虽然view是包含于一个activity ...

  3. Samung Galaxy III I535 黑砖救活经过

    昨天不小心把手机给搞成黑砖了,如下是昨天发帖求助,结果还没审核过,晕. http://bbs.zhiyoo.com/forum.php?mod=viewthread&tid=9673138&a ...

  4. OSCHina技术导向:Java电子商务平台OFBiz

    OFBiz 是开放的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级.跨平台.跨数据库.跨应用服务器的多层.分布式电子商务类WEB应用系统的框 ...

  5. centos minimal Bind 主从服务器部署

    实验环境 两台虚拟机BindM和BindS,装的系统都是centos6.3 minimal   IP地址 主机名hostname 主DNS服务器 192.168.137.102 bindm.cas.c ...

  6. 【转】Awk 命令学习总结、AWk命令系列学习(linux shell&rpar;

    前面的话 学习linux 的同人,都知道linux shell文本处理能力非常强大.有一组强大的文本处理工具:grep,sed,awk . 其中grep 经常用作查找匹配文本.sed用作文本编辑替换. ...

  7. 17&lowbar;Android中Broadcast详解&lpar;有序广播,无序广播&rpar;最终广播&comma;Bundle传递参数,传递参数的时候指定权限

     1  Broadcast是Android中的四大组件之一,他的用途很大,比如系统的一些广播:电量低.开机.锁屏等一些操作都会发送一个广播. 2  广播被分为两种不同的类型:"普通广播( ...

  8. ISP PIPLINE &lpar;十二&rpar; Sharpening

    什么是sharpening? 不解释,从左到右为sharpen , 从右到左为blur. 简单理解为边缘增强,使得轮廓清晰.增强对比度. 如何进行sharpening? 下面是实际sharpen的过程 ...

  9. Integer&period;parseInt vs Integer&period;valueOf

    一直搞不清楚这两个有什么区别.刚才特意查了一下帖子. Integer.parseInt 返回的是 primitive int Integer.valueOf  返回的是 Integer Object ...

  10. blfs(systemd版本)学习笔记-安装lrzsz软件包实现ssh远程传输文件到lfs系统

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 安装lrzsz软件包实现ssh远程传输文件到lfs系统 这个软件包在lfs系列的书中没有,这里是参照lrzsz官网的说明进行编译 ...