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 ...
随机推荐
- github/python/ show me the code 25题(二)
第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示: { "1":["张三",150,120,100], &q ...
- CAD教程/视频教程/软件类专题资料免费下载整理合集
CAD教程&视频教程类专题资料免费下载 资源列表:http://www.xiaodianlv.com/group/cad/ [1] <AUTOCAD2012中文版全套视频教程大合集> ...
- oracle dataguard 角色切换
- (92) Is there a better crawler than Scrapy? - Quora
(92) Is there a better crawler than Scrapy? - Quora Is there a better crawler than Scrapy?Edit
- Highlight On Mouseover Effect With JQuery
How to get the xpath by clicking an html element How to get the xpath by clicking an html element Qu ...
- C/C++指针的指针(**p)和指针的引用(*&)使用案例分析
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> ...
- HTTP 错误
问题描述: HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. 解决办法: win7 ...
- 关于ue上传图片到七牛云设置key
多图上传设置key: dialogs文件下面,image文件下面的image.html,链接webuploader.js,不链接webuploader.min.js webuploader.js里面 ...
- canvas绘制弹跳小球
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- 解决spark运行中failed to locate the winutils binary in the hadoop binary path的问题
1.下载hadoop-common-2.2.0-bin并解压到某个目录 https://github.com/srccodes/hadoop-common-2.2.0-bin 2.设置hadoop.h ...