Poj 3903 Stock Exchange(LIS)
一、Description
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
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
For each set of data the program prints the result to the standard output from the beginning of a line.
二、题解
这道题目是典型的求最长递增序列的问题,在之前有关于LIS的分析最长递增子序列(LIS)。
三、java代码
import java.util.Scanner;
public class Main{
static int MAXN = 100005;
static int[] a=new int [MAXN];
static int[] MaxV=new int [MAXN];
static int len,n;
static int BinSearch(int[] MaxV, int size, int x){
int left = 0, right = size-1;
while(left <= right){
int mid = (left + right) / 2;
if(MaxV[mid] < x){
left = mid + 1;
}else{
right = mid - 1;
}
}
return left;
}
static int getLIS(int[] arr){
len = 1;
MaxV[0] =arr[0];
for(int i = 1; i < n; ++i){
if(arr[i] > MaxV[len-1]){
MaxV[len++] = arr[i];
}else{
int pos = BinSearch(MaxV,len,arr[i]);
MaxV[pos] = arr[i];
}
}
return len;
}
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int i;
while(cin.hasNext()){
n=cin.nextInt();
for(i=0;i<n;i++){
a[i]=cin.nextInt();
}
System.out.println(getLIS(a));
}
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Poj 3903 Stock Exchange(LIS)的更多相关文章
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- POJ 3903 Stock Exchange(LIS || 线段树)题解
题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚 ...
- 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(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
- LIS(nlogn) POJ 3903 Stock Exchange
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...
- POJ 1860 Currency Exchange(Bellman-Ford)
https://vjudge.net/problem/POJ-1860 题意: 有多种货币,可以交换,有汇率并且需要支付手续费,判断是否能通过不断交换使本金变多. 思路: Bellman-Ford算法 ...
- POJ 3903 Stock Exchange 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
随机推荐
- swap 内存不足
参考:https://stackoverflow.com/questions/5682854/why-is-the-linker-terminating-on-me-when-i-build-clan ...
- linux sort按照指定列排序
sort怎样按指定的列排序0000 27189 41925425065f 15 419254250663 7 419254250675 5 419254250691 76 419254250693 2 ...
- Kindeditor 编辑区样式结构
ke-container ke-toolbar ke-edit ke-edit-iframe ke-edit-area ke-statusbar
- Zookeeper启动Permission denied
Zookeeper 查询状态,出现如下问题: JMX enabled by default Using config: /usr/zookeeper/zookeeper-/bin/../conf/zo ...
- 每天一个Linux命令(36)ps命令
Linux中的ps命令是Process Status的缩写. ps命令用于报告当前系统的进程状态.可以搭配kill指令随时中断.删除不必要的程序. (1)用法: ...
- 面向对象分析与设计(C++)课堂笔记
第一次课: 对象是程序设计最基本的单元 对象:对象标识.属性.操作(对象标识又分为内部标识.外部标识) 三三制原则 继承:英文语义”is a kind of” 自动的拥有或隐含的复制 虚基类:解决多继 ...
- [原创]java WEB学习笔记39:EL中的运算符号(算术运算符,关系运算符,逻辑运算符,empty运算符,条件运算符,括号运算符)
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 【leetcode刷题笔记】Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- Referrer-Policy常见属性
Referrer-Policy(来源协议)用来规定什么情况下显示Referer字段及refer字段内显示多少信息. 备注: referer实际上是对referrer的误写,因为写错的人多了也就正确了. ...
- el表达式判断字符串相等
el表达式判断字符串相等 Java code 1 ${"a" == "a"} ${"b" eq "b"} 都可以 & ...