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. ...
随机推荐
- AndroidStudio项目移植到Eclipse
原文件结构: 在AndroidStudio中 main目录对应eclipse中的src目录 可以看看每个文件夹下的目录 没有src或者main这些文件夹的都可以删掉 我这里只有app下的东西是需要留着 ...
- flash builder 4 编译器参数
accessible=true|false 是否具有可理解性(如为残疾人提供方便的性能) actionscript-file-encoding | 设置文件编码,如Shitf_JIS advanced ...
- 修改项目工程名 iOS
结合这两篇原文: http://www.cocoachina.com/ios/20150104/10824.html http://jingyan.baidu.com/article/0964eca2 ...
- centos5.5 安装git
查看centos版本 # cat /etc/redhat-release CentOS release 5.5 (Final) 安装git 下载: 如果有老版本的git: #git clone git ...
- 「OC」 多态
一.基本概念 多态在代码中的体现,即为某一类事物的多种形态,OC对象具有多态性.必须要有继承,没有继承就没有多态. 在使用多态时,会进行动态检测,以调用真实的对象方法. 多态在代码中的体现即父类指针指 ...
- Quiz 6b Question 7————An Introduction to Interactive Programming in Python
Question 7 Convert the following English description into code. Initialize n to be 1000. Initiali ...
- BZOJ 1617: [Usaco2008 Mar]River Crossing渡河问题( dp )
dp[ i ] = max( dp[ j ] + sum( M_1 ~ M_( i - j ) ) + M , sum( M_1 ~ M_i ) ) ( 1 <= j < i ) 表示运 ...
- 纯css画哆啦A梦
今天有点无聊,照着网上的图写了个哆啦A梦,无技术可言,纯考耐心. <!doctype html> <html lang="en"> <head> ...
- C陷阱与缺陷(三)
第三章 语义陷阱 3.1 指针与数组 C语言中只有一维数组,而且数组的大小必须字编译期就作为一个常数确定下来.数组中的元素可以是另外一个数组.任何一个数组下标运算都等同于一个对应的指针运算.int a ...
- FPGA知识大梳理(二)verilogHDL语法入门(1)
此文是写给0基础学习者,也是对自己知识点总结水平的考验. 对于有C基础的人来说,学习verilog应该是轻而易举 —— 类比法学习. 第一步:格式. 对于C来说我们前面会写 ‘include“std ...