(●'◡'●)

#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. win7、win8.1淡绿色护眼模式设置

    Win7设置: 右击桌面 -> 个性化 -> 窗口颜色 -> 高级外观设置 选中 -> 项目:窗口     颜色:其他 修改:色调  饱和度 亮度 红  绿  蓝 添加到自定义 ...

  2. js操作符总结

    算数操作符加法操作符(+),减法操作符(-),除法操作符(/),乘法操作符(*)还可以把多种操作组合在一起:1+4*5避免产生歧义,可以用括号把不同的操作分隔开来:1+(4*5):(1+4)*5变量可 ...

  3. iOS NSNotificationCenter 移除通知带来的crash

    Where to remove observer for NSNotification? 在dealloc方法中移除通知观察者带来crash NSNotificationCenter中的通知消息已经发 ...

  4. neovim的新体验

    A. 缘由  vim下的CtrlP插件好用,但是当文件较多时,不能很快检索,时有卡死的情况发生.听说neovim引入了很多新的功能,例如异步处理,job管理等. B. 安装neovim1. Ubunt ...

  5. 原生javascript扫雷游戏

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. [转]numpy性能优化

    转自:http://blog.csdn.net/pipisorry/article/details/39087583 http://blog.csdn.net/pipisorry/article/de ...

  7. Rails 执行 rails server 报错 Could not find a JavaScript runtime

    gem install 'execj' gem install 'therubyrace' Ubuntu install Node.js(ubuntu) sudo apt-get install no ...

  8. 使用 Python Mock 类进行单元测试

    数据类型.模型或节点——这些都只是mock对象可承担的角色.但mock在单元测试中扮演一个什么角色呢? 有时,你需要为单元测试的初始设置准备一些“其他”的代码资源.但这些资源兴许会不可用,不稳定,或者 ...

  9. 【优先队列】-HDU4546比赛难度

    比赛难度 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  10. JSON.toJSONString的jar包问题

    toJSONString()方法的jar包不在json-lib中,简单点阿里巴巴给我们封装好的json包,也是开源的alibaba.fastjson.JSON,网上搜fastjson应该就有了.