POJ3903Stock Exchange&&POJ1631Bridging signals最长上升子序列 &&POJ1887Testing the CATCHER(最长下降子序列)(LIS模版题)
题目链接:http://poj.org/problem?id=3903
题目链接:http://poj.org/problem?id=1631
题目链接:http://poj.org/problem?id=1887
题目解析:
这两道题都是直接求最长上升子序列,没什么好说的。
POJ 3903这题n为1000000,如果用n^2的算法肯定超时,所以要选择nlogn的算法。都是简单题。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define eps 1e-9
using namespace std;
int n,len,a[],d[];
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int we;
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
len=;
d[len]=a[];
for(int i=; i<=n; i++)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("%d\n",len);
}
return ;
}
POJ1631:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define eps 1e-9
using namespace std;
int n,len,a[],d[];
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int we,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
len=;
d[len]=a[];
for(int i=; i<=n; i++)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("%d\n",len);
}
return ;
}
POJ1887Testing the CATCHER:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int n,a[],d[],len;
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int tt,we,K=;
while(scanf("%d",&a[])!=EOF&&a[]!=-)
{
tt=;
while(scanf("%d",&a[++tt])!=EOF&&a[tt]!=-)
;
tt-=;
len=;
d[len]=a[tt];
for(int i=tt-; i>=; i--)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("Test #%d:\n",++K);
printf(" maximum possible interceptions: %d\n\n",len);
}
return ;
}
POJ3903Stock Exchange&&POJ1631Bridging signals最长上升子序列 &&POJ1887Testing the CATCHER(最长下降子序列)(LIS模版题)的更多相关文章
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- 最长下降子序列O(n^2)及O(n*log(n))解法
求最长下降子序列和LIS基本思路是完全一样的,都是很经典的DP题目. 问题大都类似于 有一个序列 a1,a2,a3...ak..an,求其最长下降子序列(或者求其最长不下降子序列)的长度. 以最长下降 ...
- 最长不下降子序列(LIS)
最长上升子序列.最长不下降子序列,解法差不多,就一点等于不等于的差别,我这里说最长不下降子序列的. 有两种解法. 一种是DP,很容易想到,就这样: REP(i,n) { f[i]=; FOR(j,,i ...
- 最长不下降子序列 O(nlogn) || 记忆化搜索
#include<stdio.h> ] , temp[] ; int n , top ; int binary_search (int x) { ; int last = top ; in ...
- BUY LOW, BUY LOWER_最长下降子序列
Description The advice to "buy low" is half the formula to success in the bovine stock mar ...
- tyvj 1049 最长不下降子序列 n^2/nlogn
P1049 最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 ...
- 最长不下降子序列的O(n^2)算法和O(nlogn)算法
一.简单的O(n^2)的算法 很容易想到用动态规划做.设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i&g ...
- 最长不下降子序列//序列dp
最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 最长不下降 ...
- 【tyvj】P1049 最长不下降子序列
时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数 第二行n个数 输出格式 最长不下降子序列的长度 测 ...
随机推荐
- PyCharm中设置菜单字体大小
file——>setting,然后选择appearance,下图右侧红色边框中的内容即设置菜单的字体和大小
- MyBatis 最强大的特性之一就是它的动态语句功能
MyBatis 最强大的特性之一就是它的动态语句功能.如果您以前有使用JDBC或者类似框架的经历,您就会明白把SQL语句条件连接在一起是多么的痛苦,要确保不能忘记空格或者不要在columns列后面省略 ...
- zabbix2.0 添加自定义监控项
1. key的创建 客户端配置文件如下: root@192.168.100.254:/usr/local/zabbix/sbin# egrep -v "(^#|^$)" ../et ...
- mysql存储过程,获取指定数据库的某个表的字段信息
DROP PROCEDURE IF EXISTS Proc; DELIMITER //CREATE PROCEDURE Proc(database_name varchar(50),table_nam ...
- fzu 1330:Center of Gravity(计算几何,求扇形重心)
Problem 1330 Center of Gravity Accept: 443 Submit: 830Time Limit: 1000 mSec Memory Limit : 327 ...
- hrbustoj 1318:蛋疼的蚂蚁(计算几何,凸包变种,叉积应用)
蛋疼的蚂蚁 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 39(22 users) Total Accepted: 26 ...
- Objective-C 成员变量
成员变量的访问权限 Objective-C中的成员变量有以下三种属性 public(外部及其子类可访问) protected(子类可访问,外部不可访问) private(外部及其子类不可访问) 默认情 ...
- matlab判断图像是彩色图还是灰度图
matlab怎样看图像是彩色还是灰度_莹莹_新浪博客 http://blog.sina.com.cn/s/blog_76088a1f0101diq0.html 解决一: isrgb(A) 如果A是RG ...
- MySQL--执行mysql脚本及其脚本编写
http://www.cnblogs.com/kex1n/archive/2010/03/26/2286504.html
- 理解javascript函数调用和“this”
http://blog.csdn.net/littlechang/article/details/8180550