(●'◡'●)

#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. Android设备标识符的使用

    设备ID(DeviceId) 获取办法 android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) con ...

  2. shrio登录验证

    shiro的认证过程也就是判断用户名和密码的过程,在认证过程中,用户需要提交实体信息(用户名)(Principals)和凭据信息(密码)(Credentials)来判断用户是否合法,最常见的" ...

  3. (转载)ANDROID STRINGS.XML 中的特殊字符转义

    今天项目碰到个转义特殊字符的问题,网上搜索看到,故转载,已标明出处: 项目中要在string.xml 中显示特殊符号.如@号冒号等.直接写肯定不行啦 只能考虑使用ASCII码进行显示.在XML中空格符 ...

  4. linux for 使用

    第一种:命令使用方法 例子1: cat test.txt 1 2 3 for i in $(cat test.txt) do echo $i done 例子2: for i in 1 2 3 4 do ...

  5. 《Intel汇编第5版》 条件汇编伪指令

    一.条件汇编伪指令和宏使用可以使汇编程序更加灵活 二.通过伪指令来检查函数的参数是否为空,如果为空则输出警告信息 INCLUDE Irvine32.inc includelib Irvine32.li ...

  6. Fedora25

    Fedora默认情况是没有装flash的,首先输入https://get.adobe.com/flashplayer/?loc=cn,选择.rpm包,点击立即下载,下载完成后进到download目录, ...

  7. As input tri-stated

    前些日子正好看到了riple兄的<一波三折--危险的"未分配"引脚>一文,颇受启发.正好最近也遇上了类似的问题,也可谓一波三折,还好最后摆平了,要不煮熟的鸭子可就要飞了 ...

  8. 【for陷阱】遍历的同时删除元素

    今晚,哦不,是昨晚了,想删除空行时,给for语句和列表坑得好惨!!! 一般来说,删除字符串的空行有以下几种常见的方法~(然而我竟然想不出来) 假设我们要把下面的字符串之间的空行给去掉 # coding ...

  9. NSDateComponents

    NSDateComponents将时间表示成适合人类阅读和使用的方式, 首先要遵循某种历法 NSCalendar * cal = [NSCalendar currentCalendar]; 有三种用法 ...

  10. html5获取图片的宽高

    var fr = new FileReader; fr.readAsDataURL($("#inputFileId").files[0]); fr.onload = functio ...