POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E
题目:
Description
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.
Sample Input
6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1
Sample Output
3
1
1
Hint
#include<cstdio>
#include<iostream>
using namespace std; const int maxn=; int i;
int n,cnt;
int a[maxn],b[maxn]; int LIS()
{
cnt=;
b[]=;
for(i=;i<n;i++)
{
if(cnt==||a[i]>b[cnt])
{
cnt++;
b[cnt]=a[i]; //保存最长上升子序列的个数
}
else
{
int l=,r=cnt;
while(l<=r) //二分比较a[]和b[]中值的大小关系
{
int mid=(l+r)/;
if(a[i]>b[mid])
l=mid+;
else
r=mid-;
}
b[l]=a[i]; }
}
return cnt;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
scanf("%d",&a[i]);
LIS();
printf("%d\n",cnt);
}
return ;
}
开始调试的时候,只要输入一个数就输出1,一直没有找出来错误,找别人帮忙来看也没有找出,后来才发现是因为写的时候把scanf中的%d写成了d%,真是好坑啊。。。。。
下次一定要好好注意这些小地方
POJ 3903 Stock Exchange (E - 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)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- POJ 3903 Stock Exchange(LIS || 线段树)题解
题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚 ...
- 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 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- POJ 3903 Stock Exchange 【最长上升子序列】模板题
<题目链接> 题目大意: 裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找. O(nlogn)算法 #i ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
随机推荐
- 【LeetCode题意分析&解答】43. Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- python 关于dict的一些总结
总结了一些关于字典的小技巧或者注意的地方. 使用zip创建字典 创建字典有以下三种方法 dict(a=1, b=2, c=2) dict([(a,1), (b,2), (c,3)]) dict({a: ...
- Eclipse中搭建Python开发环境
转载:http://www.cnblogs.com/realh/archive/2010/10/04/1841907.html Eclipse+PyDev环境搭建 1.准备工作 JDK6 Java 开 ...
- JAVA并发,锁与方法
引自:<thinking in java> synchronized void f(){/* ... */}; synchronized void g(){/* ... */}; 所有对象 ...
- CCNA实验(3) -- RIP
RIP协议分为版本1和版本2,均具备以下特征:1.是距离向量路由协议2.使用跳数(Hop Count)作为度量值3.默认路由更新周期为30秒4.管理距离(AD)为1205.支持触发更新6.最大跳数为1 ...
- nyist 202 红黑树(二叉树中序遍历)
旋转对中序遍历没有影响,直接中序输出即可. #include <iostream> #include <cstdio> using namespace std; int n; ...
- xcode 不值钱的动画UIImageView
了解 animateWithDuration方法 制作动画变得不值钱 代码创建一个UIImageView 后加入self.view 容器中 调用点击屏幕touchesBegan 方法执行动画 #imp ...
- .net mvc System.Web.Optimization 、System.Data.Entity.Infrastructure找不到
在MVC4的开发中,如果在App_Start目录下BundleConfig.cs类没有找不到引用System.Web.Optimization,可以使用程序包管理控制台进行安装到使用的项目 打开 工具 ...
- git版本工具(团队开发常用)
1.创建一个版本库 mkdir repository //创建一个文件夹 git init //把目录编程git可以管理的仓库 2.提交文件到版本库 git add test.tx ...
- ORACLE 计算节假日
create or replace function get_workday(starTime in date,endTime in date) return number is Weekends n ...