题意:

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

思路:

没看仔细还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. 关于IP地址与MAC地址(网卡硬件地址)的区别小谈

    IP地址是指Internet协议使用的地址,而MAC地址是Ethernet协议使用的地址. IP地址与MAC地址之间并没有什么必然的联系,MAC地址是Ethernet NIC(网卡)上带的地址,为48 ...

  2. 【算法编程】找出仅仅出现一次的数-singleNumber

    题目意思: 一个数值数组中,大部分的数值出现两次,仅仅有一个数值仅仅出现过一次,求编程求出该数字. 要求,时间复杂度为线性,空间复杂度为O(1). 解题思路: 1.先排序.后查找. 因为排序的最快时间 ...

  3. ACM-ICPC如何起步[转]

    ACM-ICPC如何起步 刚刚绝定投身ACM-ICPC的同学先要过两关. 第一关:程序设计语言 如果学校有开设相关课程,则省去了很多麻烦.如果没有则可以选择<程序设计导引及在线实践>作为教 ...

  4. this、call和apply、bind

    this关键字: JavaScript的this关键字,总是指向一个对象,具体指向哪个对象,是根据运行时函数指向环境动态绑定的.简单来说,this就是谁调用指向谁.具体使用中,this的指向,大致可以 ...

  5. 利用easyUI的combobox打造自己主动提示组件

    自己主动提示是时下一个非常流行的功能,比方说百度.谷歌的搜索输入框都使用到了这么一个功能. 因为easyUI的combobox设计师已经考虑到了这个功能.所以仅仅需简单几步我们能够轻松打造自己的自己主 ...

  6. Hadoop 0.20.2+Ubuntu13.04配置和WordCount測试

    事实上这篇博客写的有些晚了.之前做过一些总结后来学校的事给忘了,这几天想又一次拿来玩玩发现有的东西记不住了.翻博客发现居然没有.好吧,所以赶紧写一份留着自己用吧.这东西网上有非常多,只是也不是全然适用 ...

  7. ArchLinux最小化安装 必备库 常用命令

    铸成强大的工作站环境——ArchLinux最小化安装 所有问题归结起来,只是一个问题:ArchLinux最小化安装,需要安装哪些包? 1.bash//最基本的Bash Shell(必须)2.bzip2 ...

  8. Typescript 常见写法

    一.Typescript 中数组 let list: number[] = [1, 2, 3]; let list: Array<number> = [1, 2, 3];

  9. ES6 解构赋值的常见用途,很强大

    字符串 var [a,b,c,d,e] = "hello"; console.log(a); // h console.log(b); // e console.log(c); / ...

  10. codeforces 443 B. Kolya and Tandem Repeat 解题报告

    题目链接:http://codeforces.com/contest/443/problem/B 题目意思:给出一个只有小写字母的字符串s(假设长度为len),在其后可以添加 k 个长度的字符,形成一 ...