C. DZY Loves Sequences
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY has a sequence a, consisting of
n integers.

We'll call a sequence ai, ai + 1, ..., aj
(1 ≤ i ≤ j ≤ n) a subsegment of the sequence
a. The value (j - i + 1) denotes the length of the subsegment.

Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.

You only need to output the length of the subsegment you find.

Input

The first line contains integer n (1 ≤ n ≤ 105). The next line contains
n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In a single line print the answer to the problem — the maximum length of the required subsegment.

Sample test(s)
Input
  1. 6
  2. 7 2 3 1 5 6
Output
  1. 5
Note

You can choose subsegment a2, a3, a4, a5, a6
and change its 3rd element (that is a4) to 4.

题意就是, 你能够改变字符串中的一个字符。 就出其最长的连续字串

如案列, 7 2 3 1 5 6 —————7 2 3  4 5 6

输出即为5.

  1.  
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<vector>
  7. #include<queue>
  8. #include<sstream>
  9. #include<cmath>
  10.  
  11. using namespace std;
  12.  
  13. #define f1(i, n) for(int i=0; i<n; i++)
  14. #define f2(i, m) for(int i=1; i<=m; i++)
  15. #define f3(i, n) for(int i=n; i>=1; i--)
  16. #define f4(i, n) for(int i=1; i<=n; i++)
  17. #define f5(i, n) for(int i=2; i<=n; i++)
  18. #define M 1005
  19.  
  20. const int INF = 0x3f3f3f3f;
  21. int n, a[100005], b[100005];
  22.  
  23. int main()
  24. {
  25. cin>>n;
  26. f4(i, n)
  27. cin>>a[i];
  28. b[1]=1;
  29. f5(i, n)
  30. {
  31. b[i]=1;
  32. if (a[i]>a[i-1])
  33. b[i]=b[i-1]+1;
  34. }
  35. int ans=-INF;
  36. f3(i, n)
  37. {
  38. if (b[i]==n)
  39. ans=max(b[i], ans);
  40. else
  41. ans=max(ans, b[i]+1);
  42. if (a[i-b[i]+1]-1>a[i-b[i]-1])
  43. ans=max(ans,b[i]+b[i-b[i]]);
  44. if (a[i-b[i]+2]-1>a[i-b[i]])
  45. ans=max(ans,b[i]+b[i-b[i]]);
  46. }
  47. cout<<ans<<endl;
  48. return 0;
  49. }

Codeforces Round #FF (Div. 2):C. DZY Loves Sequences的更多相关文章

  1. Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash

    A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry

    B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  5. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划

    A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...

  6. Codeforces Round #FF (Div. 2) 题解

    比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit p ...

  7. Codeforces Round #FF (Div. 1)-A,B,C

    A:DZY Loves Sequences 一開始看错题了. .sad. 题目非常easy.做法也非常easy.DP一下就好了. dp[i][0]:到当前位置,没有不论什么数改变,得到的长度. dp[ ...

  8. Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列

    B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...

  9. Codeforces Round #FF (Div. 1) B. DZY Loves Modification

    枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...

随机推荐

  1. HDU 2067 小兔的棋盘

    题解:卡特兰数的几何意义,所以答案就是卡特兰数的两倍 #include <cstdio> #include <iostream> using namespace std; #d ...

  2. 笔试题:金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出

    收集这道题目原因是以前做过,但是实现的很麻烦,这次看到别人写的感觉简单易懂. 从一个pdf看到,出处就不贴了 = .= public class RenMingBi { private static ...

  3. C#实现的内存分页机制的一个实例

    C#实现的内存分页机制的一个实例 //多页索引表管理类(全局主索引表管理类) public class MuliPageIndexFeatureClass : IDisposable { protec ...

  4. 不可不知的HTML优化技巧

    如何提升Web页面的性能,很多开发人员从多个方面来下手如JavaScript.图像优化.服务器配置,文件压缩或是调整CSS. 很显然HTML 已经达到了一个瓶颈,尽管它是开发Web 界面必备的核心语言 ...

  5. nodejs partials 分布视图

    在学习<node.js开发指南>nodejs partials view时,怎么都不能运行成功.经过艰苦探索,终于成功了,分享一下. Cause: nodejs 的express 版本之间 ...

  6. Xcode - 详解真机测试步骤

    第一种从iOS9.0之后推出的免费开发者账号 1.注册开发者 * 注册Apple ID * 使用Apple ID登录苹果开发者中心,注册成为开发者 * 此过程为免费,只是为了让普通的Apple ID具 ...

  7. js 精美倒计时

    精美倒计时*{ padding:0; margin:0;}.colockbox{width:250px;height:30px;background:url(/jscss/demoimg/201312 ...

  8. 杭电oj find your present (2)

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  9. BZOJ 3175: [Tjoi2013]攻击装置( 匈牙利 )

    黑白染成二分图, 然后不能同时选的就连边, 最大匹配数为m, t为不能放的数目, 则题目所求最大点独立集为 n*n-m-t -------------------------------------- ...

  10. NSData 数据转换

    NSData,数据,当我们需要把一些信息写入到文件里或发送到网络上,我们需要把这些数据转换下,变成纯粹的0.1字符流 数组转 NSData NSData *GLYtime = [NSKeyedArch ...