题意:

求一个连续的最长子序列长度;

思路:

没看仔细还wa1了…以为LIS…

然后写了尺取吧。。。= =太不仔细了。不过收获是LIS特么写挫了然后看了学长的blog<-点我…

题目的挫code…

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL; const int N=1e5+10; int n;
int a[N]; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]); int s,t,ans,temp;
s=t=1;
ans=1;
temp=0;
while(s<=n)
{
while(t+1<=n&&a[t]<a[t+1])
{
temp=t-s+2;
t++;
}
s=t+1;
t=t+1;
ans=max(temp,ans);
}
printf("%d\n",ans);
return 0;
}

LIS的nlogn写法:

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL; const int N=1e5+10; int n;
int dp[N];
int a[N]; int kill(int x,int len)
{
int s=1,t=len;
while(s<=t)
{
int mid=(s+t)/2;
if(dp[mid]>=x)//这里等于也写成末尾-1,主要是最后返回起点,因为最重要的是要找到哪个点比他大然后就放那
t=mid-1;
else
s=mid+1;
}
return s;
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]); int len=1,j; dp[1]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]<=dp[1]) //如果a[i]比dp数组的第一位小;
j=1;
else if(a[i]>dp[len]) //如果a[i]比dp数组最大的还大;
j=++len;
else
j=kill(a[i],len); //寻找在dp数组的位置;
dp[j]=a[i];
}
printf("%d\n",len);
return 0;
}

Codeforces702A - Maximum Increase【尺取】的更多相关文章

  1. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  2. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  3. Intense Heat(前缀和或尺取)

    The heat during the last few days has been really intense. Scientists from all over the Berland stud ...

  4. HDU-4123-树形dp+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  6. NOJ 1072 The longest same color grid(尺取)

    Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit in ...

  7. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  9. cf702A Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 零售连锁行业SOA化解决方式

    零售连锁行业面临的问题 1.店铺老化.营销手段单一落后. 2.管理模式的不科学,我国零售企业在起家时候并没有一套完好的科学的管理及考评系统的存在.而且在企业的发展过程中并未学习建立.对于人才的吸引.培 ...

  2. 手机号码归属地查询免费api接口代码

    依据手机号码查询用户的卡类型.运营商.归属地.区域等信息. 手机归属地实体类 package org.wx.xhelper.model; /** * 手机归属地 * @author wangxw * ...

  3. 线程池实例:使用Executors和ThreadPoolExecutor

    线程池负责管理工作线程,包含一个等待执行的任务队列.线程池的任务队列是一个Runnable集合,工作线程负责从任务队列中取出并执行Runnable对象. java.util.concurrent.ex ...

  4. java8 stream sorted

    1.对象类型配列 List<Person> list = Arrays.asList( new Person(22, "shaomch", "man" ...

  5. 使用外部 toolchain 编译 openwrt

    默认编译 openwrt 时会先编译一套 toolchain. 这个步骤耗时较长. 使用外部 toolchain 可以多个 project 共用一套 toolchain , 而且也不重再编译它了. 省 ...

  6. const& 的东西

    class_name ( class_name const & source ); 是拷贝构造函数的标准声明. 它和如下声明是一个意思 class_name ( const class_nam ...

  7. Apach Web Server区别于其他应用服务器的主要特点是什么?

    Web服务器一般指的是处理静态请求或转发http请求的服务器,而应用服务器一般是用来处理动态请求的服务器.

  8. 在线安装Ganglia3.6.0,nginx+php搭建gweb,绝对通过

    环境:CentOS6.5 minimal 目标:安装Ganglia核心组件(gmond, gmetad, gmetric, gstat, libganglia).Ganglia web 准备 yum增 ...

  9. Java 快速失败( fail-fast ) 安全失败( fail-safe )

    原文:http://www.cnblogs.com/ygj0930/p/6543350.html 快速失败( fail-fast ):当你在迭代一个集合的时候,如果有另一个线程正在修改你正在访问的那个 ...

  10. yum下载对应内核版本的kernel-devel

    1 查看内核版本 uname -r 2 查看目前已有的kernel-devel uname -a ; rpm -qa kernel\* | sort 3 下载对应版本 $ sudo yum insta ...