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. ...
随机推荐
- [Asp.net]常见word,excel,ppt,pdf在线预览方案(转)
引言 之前项目需要,查找了office文档在线预览的解决方案,顺便记录一下,方便以后查询. 方案一 直接在浏览器中打开Office文档在页面上的链接.会弹出如下窗口: 优点:主流浏览器都支持. 缺点: ...
- DevExpress ASP.NET 使用经验谈(7)-ASPxTreeList控件使用
这一节,将介绍ASPxTreeList控件的使用,首先,我们增加一个标准地址库表AddressGB, 建表语句如下: CREATE TABLE [dbo].[AddressGB]( [Code] [v ...
- linq to sql用partial扩展属性,创建一个部分类(用于多表连接)
1.在窗体中创建dataGridView显示表: using System; using System.Collections.Generic; using System.ComponentModel ...
- 解决虚拟内存不够导致Eclipse is not responding
安装目录下eclipse.ini中: 修改参数至必要大小. e.g. -vmargs-Djava.net.preferIPv4Stack=true-Dosgi.requiredJavaVersion= ...
- json对象的操作,json工具
项目中经常用到json,现在把写了几个js函数,用来获取json对象或者json字符串的长度,以及获取其的key值,value值,并且返回. 这样以后可以直接拿来用,可以省去不少麻烦,也方便以后查看. ...
- div+css 布局下兼容IE6 IE7 FF常见问题
div+css 布局下兼容IE6 IE7 FF常见问题 收藏 所有浏览器 通用 (市面上主要用到的IE6 IE7 FF)height: 100px; IE6 专用 _height: 100px; IE ...
- 配置分割Tomcat日志
安装cronolog 官网下载:http://cronolog.org/usage.html ./configuremake;make install 或者 yum install cronolog ...
- Basic REST API Design
- 高级UNIX环境编程11 线程
<pthread.h> pthread_equal pthread_self(void) pthread_create() pthread_close() pthread_join() p ...
- clear伪类使用
都知道float会脱离文档流 用什么办法撑开父元素呢? 手动在本区块的所有float元素之后加上一个块元素并对其添加clear:both 可以 但是这样还要再去修改html页面 而且多了一个仅仅是 ...