Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
1 second
256 megabytes
standard input
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.
The first line contains integer n (1 ≤ n ≤ 105). The next line contains
n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
In a single line print the answer to the problem — the maximum length of the required subsegment.
6
7 2 3 1 5 6
5
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.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++)
#define f3(i, n) for(int i=n; i>=1; i--)
#define f4(i, n) for(int i=1; i<=n; i++)
#define f5(i, n) for(int i=2; i<=n; i++)
#define M 1005 const int INF = 0x3f3f3f3f;
int n, a[100005], b[100005]; int main()
{
cin>>n;
f4(i, n)
cin>>a[i];
b[1]=1;
f5(i, n)
{
b[i]=1;
if (a[i]>a[i-1])
b[i]=b[i-1]+1;
}
int ans=-INF;
f3(i, n)
{
if (b[i]==n)
ans=max(b[i], ans);
else
ans=max(ans, b[i]+1);
if (a[i-b[i]+1]-1>a[i-b[i]-1])
ans=max(ans,b[i]+b[i-b[i]]);
if (a[i-b[i]+2]-1>a[i-b[i]])
ans=max(ans,b[i]+b[i-b[i]]);
}
cout<<ans<<endl;
return 0;
}
Codeforces Round #FF (Div. 2):C. DZY Loves Sequences的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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] + ...
- 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 ...
- Codeforces Round #FF (Div. 2) 题解
比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit p ...
- Codeforces Round #FF (Div. 1)-A,B,C
A:DZY Loves Sequences 一開始看错题了. .sad. 题目非常easy.做法也非常easy.DP一下就好了. dp[i][0]:到当前位置,没有不论什么数改变,得到的长度. dp[ ...
- 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 ...
- 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. ...
随机推荐
- mget 同时获取
mget 同时获取: http://192.168.32.81:9200/ _mget POST { "docs" :[ { "_index":"li ...
- Hibernate_13_QBC查询
Employee类.Department类.SessionFactoryTools类.Employee.hbm.xml文件.Department.hbm.xml文件.Hibernate.cfg.xml ...
- Java之旅(一)---说说“异常”那些事
从開始学习VB,就听说过"异常",认为异常处理就是加上try..catch,不让错误抛出给用户,到此为止,不要再往下问了,再问也不会了.这就是那时候的理解.如今随时项目经验的 ...
- CSS的display、hover、overflow、©(版权符号)、borer-radius(边框圆角)
一.display: none 隐藏 block显示 visibility:hidden隐藏 visible显示 display:none和visibility:hidden这两个属性对应的值 ...
- Visual Studio Tools for Unity安装及使用
Visual Studio Tools for Unity安装及使用 转载自:CSDN 晃了一下,10.1到现在又过去两个月了,这两个月什么也没有学,整天上班下班,从这周末开始拾起unity,为了年后 ...
- dedecms的入门使用
前段时间(其实也很远了)一直在学习dedecms,这里对前段时间的学习做一个总结. dedecms学习网址:http://help.dedecms.com/v53
- C++对象的销毁
- json所需jar包 & js解析后台json数据
Json 所需jar包: var listxxx='<%=request.getAttribute("listxxx")%>'; // list数组 var mapx ...
- 通过Qt样式表定制程序外观(比较通俗易懂)
1. 何为Qt样式表[喝小酒的网摘]http://blog.hehehehehe.cn/a/10270.htm2. 样式表语法基础3. 方箱模型4. 前景与背景5. 创建可缩放样式6. 控制大小7. ...
- perl学习(3) 列表
列表或称为数组,和c语言中的数据类似,只是perl自己特殊的一些写法. 1.1.定义 一个列表或者数组可以包含数字,字符串,undef 值,或者任意不同类型的标量值的组合,但是这些元素的类型通常是 ...