题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E

题目:

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

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

Sample Output

  1. 3
  2. 1
  3. 1

Hint

There are three data sets. In the first case, the length L of the sequence is 6. The sequence is 5, 2, 1, 4, 5, 3. The result for the data set is the length of the longest rising trend: 3.
 
 
题意:
   一道LIS的裸题,给定一组数据,让我们求出这组数据的最大上升的序列包含元素的个数。
思路:
    要注意数据比较多,要用二分法的优化法(O(nlogn))。
 

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. const int maxn=;
  5. int a[maxn],b[maxn];
  6. int main()
  7. {
  8. int n,i,L,mid;
  9. while(scanf("%d",&n)!=EOF)
  10. {
  11. a[]=-;
  12. int count=;
  13. int Max=;
  14. for(i=;i<=n;i++)
  15. cin>>a[i];
  16. for(i=;i<=n;i++)
  17. {
  18. if(a[i]>b[count])
  19. b[++count]=a[i];
  20. else
  21. {
  22. Max=count;
  23. L=;
  24. while(L<=Max)
  25. {
  26. mid=(L+Max)/;
  27. if(b[mid]<a[i])
  28. L=mid+;
  29. else Max=mid-;
  30. }
  31. b[L]=a[i];
  32. }
  33. }
  34. cout<<count<<endl;
  35. }
  36. return ;
  37. }

POJ3903:Stock Exchange(LIS)的更多相关文章

  1. POJ 3903:Stock Exchange(裸LIS + 二分优化)

    http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. POJ3903 Stock Exchange LIS最长上升子序列

    POJ3903 Stock Exchange #include <iostream> #include <cstdio> #include <vector> #in ...

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

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

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

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

  5. poj3903 Stock Exchange(最长上升子序列)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3903">http://poj.org/problem?id=3903 Descrip ...

  6. Poj 3903 Stock Exchange(LIS)

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

  7. poj3903 Stock Exchange 二分+dp

    题目地址:http://poj.org/problem?id=3903 题目: Description The world financial crisis is quite a subject. S ...

  8. POJ 3903 Stock Exchange

    Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2954   Accepted: 1082 De ...

  9. 品友推广的投放原理 RTB:Real Time Bidding(实时竞价) DSP:Demand-Side Platform(需求方平台) 广告交易平台:AD Exchange

    总结: 1.实时竞价 0.1秒出价各个广告主出价,投放价高者: RTB(Real Time Bidding)实时竞价,是一种利用第三方技术在数以百万计的网站或移动端针对每一个用户展示行为进行评估以及出 ...

随机推荐

  1. WPF QuickStart系列之附加属性(Attached Property)

    这一篇博客是关于如何使用附加属性和创建自定义附加属性的. 1. 附加属性使用, WPF中对附加属性使用最多的莫过于对控件布局时设置控件的位置,例如在Canvas中有一个Rectangle, Ellip ...

  2. hdu 5289 rmp+二分+枚举后界 or单调队列 ****

    好题~~ 给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数,枚举后界~~ 又是一种没见过的方法,太弱了/(ㄒoㄒ)/~~ #include <cstdio ...

  3. JavaScript中call,apply和prototype

    [TOC] call()方法 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 如果没有提供 thi ...

  4. ExpandableListView 里面嵌套GridView实现高度自适应

    很早之前做过一个商城的app 也是第一次做安卓. 实现的效果如下: 因为一开始做安卓,很多写的代码都不规范,在下面上代码的地方,还请高手指点(勿喷,楼主是自尊心很强的屌丝) 这个效果要解决2个大问题, ...

  5. sqoop与mysql之间中文乱码

    sudo -u hive sqoop export --connect "jdbc:mysql://192.168.22.201/LauncherDB?useUnicode=true& ...

  6. poj 1141 区间dp+递归打印路径

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30383   Accepted: 871 ...

  7. kafka基本原理学习

    下载安装地址:http://kafka.apache.org/downloads.html  原文链接:http://www.jasongj.com/2015/01/02/Kafka深度解析 Kafk ...

  8. POJ 1743 后缀数组

    题目链接:http://poj.org/problem?id=1743 题意:给定一个钢琴的音普序列[值的范围是(1~88)],现在要求找到一个子序列满足 1,长度至少为5 2,序列可以转调,即存在两 ...

  9. SU Demo之01MakingData--02MultiShot

  10. loopback 01

    关于loopback的相关blog 安装: 官网 $ mkdir office-supplies $ cd office-supplies $ slc loopback $ slc loopback: ...