(●'◡'●)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<stack>
#include<map>
using namespace std;
typedef long long ll; int main()
{
int n,a1,a,dist1=,dist2=,l=,r=,ans=;
scanf("%d",&n);
scanf("%d",&a1);
for(int i=;i<=n;i++)
{
scanf("%d",&a);
dist1=a-a1; //根据题意:差值只能为0,1,-1
a1=a; if(dist1==) continue; //差值为0的继续往前走
if(dist1!=dist2) //差值不为0且与前一个差值不相等
{
dist2=dist1; //更新当前区间的差值
r=i;
}
else //差值不为0但与前一个差值相同(如子序列1 2 3)
{
ans=max(ans,i-l); //更新区间长度
l=r;r=i;
}
}
ans=max(ans,n-l+);
//若子序列的首尾相同(如子序列2 3 3 2),则ans=n-l+1;
printf("%d\n",ans);
return ;
}

CF 602B Approximating a Constant Range的更多相关文章

  1. Codeforces 602B Approximating a Constant Range(想法题)

    B. Approximating a Constant Range When Xellos was doing a practice course in university, he once had ...

  2. codeforce -602B Approximating a Constant Range(暴力)

    B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 256 megabytes ...

  3. FZU 2016 summer train I. Approximating a Constant Range 单调队列

    题目链接: 题目 I. Approximating a Constant Range time limit per test:2 seconds memory limit per test:256 m ...

  4. Codeforces Round #333 (Div. 2) B. Approximating a Constant Range st 二分

    B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  5. cf602B Approximating a Constant Range

    B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. Codeforces Round #333 (Div. 2) B. Approximating a Constant Range

    B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  7. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【CodeForces 602C】H - Approximating a Constant Range(dijk)

    Description through n) and m bidirectional railways. There is also an absurdly simple road network — ...

  9. #333 Div2 Problem B Approximating a Constant Range(尺取法)

    题目:http://codeforces.com/contest/602/problem/B 题意 :给出一个含有 n 个数的区间,要求找出一个最大的连续子区间使得这个子区间的最大值和最小值的差值不超 ...

随机推荐

  1. Java线程如何返回数据

    前言 当开发者从单线程开发模式过渡到多线程环境,一个比较棘手的问题就是如何在一个线程中返回数据,众所周知,run()方法和start()方法不会返回任何值. 笔者在学习<Java Network ...

  2. Android Studio利用异步任务AsyncTask发送post请求获取json数据

    syncTask,是Android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI主 ...

  3. RPC 框架原理详解

    首先了解什么叫RPC,为什么要RPC,RPC是指远程过程调用?也就是说两台服务器A,B,一个应用部署在A服务器上,想要调用B服务器上应用提供的函数/方法,由于不在一个内存空间,不能直接调用,需要通过网 ...

  4. LeetCode 213. House Robber II

    Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...

  5. Hybrid App(二)Cordova+android入门

    上一篇介绍了app开发如何选型,由于公司人员组织结构的原因(app native较少,每个月一次迭代),因此选型hybrid app. 接下来说一下环境搭建: 一.Java环境 (1)安装jdk (2 ...

  6. mysql连接失败或出现“Too many connections”错误

    mysql连接失败或出现"Too many connections"错误 # 按自己服务器的配置文件路径修改 vi /etc/my.cnf 查找:max_connections 修 ...

  7. C#基础--值类型和引用类型

    C#中大多数类型都是引用类型,只有个别特殊情况是值类型. 值类型: 枚举(enum) 结构(struct) 基础类型:int, short, char, bool....(string是引用类型) 引 ...

  8. 窗口、easyui-window、easyui-panel、easyui-linkbutton

    //窗口 <script type="text/javascript" src="js/jquery.min.js"></script> ...

  9. 获取listview当前滚动的高度

    public int getScrollY() {      View c = mListView.getChildAt(0);      if (c == null ) {          ret ...

  10. 基于jQuery弹性展开收缩菜单插件gooey.js

    首先 引入css <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel ...