C. DZY Loves Sequences

2024-05-11 03:38
文章标签 loves sequences dzy

本文主要是介绍C. DZY Loves Sequences,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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
6
7 2 3 1 5 6
Output
5
Note

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

//题意:给你一个数列,你可以改变这个数列其中任意一个数的值(只能改变一个),找出一个最大子段,其中这个子段要严格递增(只要递增就行且不能出现前后相等)

//AC代码

#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<cmath>
const int MAX=100001;
long long xx[MAX];
long long yy[MAX];
using namespace std;
int main()
{
long long n,i,j,m,t,k,As,Ae,Bs,Be,B1,B2,Max,num,a,b,p;
//while(1)
//{
cin>>n;
memset(xx,0,sizeof(xx));
memset(yy,0,sizeof(yy));
As=0;
Ae=0;
Bs=0;
Be=0;
B1=0;
B2=0;
Max=0;
a=1;
b=1;
k=0;
p=0;
cin>>t;
As=t;
xx[a]=t;
a+=1;
for(i=2;i<=n;i++)
{
cin>>m;
//cout<<"OK1"<<i<<endl;
if(t<m)
{
t=m;
xx[a]=m;
a+=1;
}
else
{
Ae=xx[a-1];
As=xx[a-2];
t=m;
yy[b]=m;
b+=1;
break;
}
}
//cout<<"OK"<<endl;
//cout<<As<<" "<<Ae<<" "<<a<<endl;
for(j=i+1;j<=n;j++)
{
cin>>m;
//cout<<m<<" zheshi"<<endl;
//cout<<"OK2 "<<j<<endl;
if(t<m)
{
t=m;
yy[b]=m;
b+=1;
}
else
{
if(j==n)
p=1;
Bs=yy[b-2];
Be=yy[b-1];
B1=yy[1];
B2=yy[2];
//cout<<Bs<<" "<<Be<<" "<<B1<<" "<<B2<<" "<<b<<" acm"<<endl;
if((a-1)==1)
{
if((b-1)==1)
{
num=2;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
else
{
num=b;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
As=Bs;
Ae=Be;
a=b;
b=1;
yy[1]=m;
yy[2]=0;
t=m;
b+=1;
//cout<<As<<" "<<Ae<<" "<<a<<endl;
}
else
{
//cout<<"000"<<endl;
if((b-1)==1)
{
num=a;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
else
{
//cout<<"111"<<endl;
if((B2-Ae>=2)||(B1-As>=2))
{
//cout<<"222"<<endl;
num=a+b-2;
if(Max<=num)
Max=num;
//cout<<As<<" "<<Ae<<" "<<a<<endl;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
else
{
if(a>b)
{
num=a;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
else
{
num=b;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
}
}
As=Bs;
Ae=Be;
a=b;
b=1;
yy[1]=m;
yy[2]=0;
t=m;
b+=1;
}
}
}
//--------------------------------------
if(p==0&&b==1)
{
num=a-1;
if(Max<=num)
Max=num;
}
if(p==0&&b!=1)
{
Bs=yy[b-2];
Be=yy[b-1];
B1=yy[1];
B2=yy[2];
//cout<<As<<" "<<Ae<<" "<<a<<" "<<B1<<" "<<B2<<" "<<b<<" yuweiwei"<<endl;
if((a-1)==1)
{
if((b-1)==1)
{
num=2;
if(Max<=num)
Max=num;
//cout<<"Max="<<Max<<endl;
}
else
{
num=b;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
//cout<<As<<" "<<Ae<<" "<<a<<endl;
}
else
{
//cout<<"000"<<endl;
if((b-1)==1)
{
num=a;
if(Max<=num)
Max=num;
//cout<<"Max="<<Max<<endl;
}
else
{
//cout<<"111"<<endl;
if((B2-Ae>=2)||(B1-As>=2))
{
// cout<<"222"<<endl;
num=a+b-2;
if(Max<=num)
Max=num;
//cout<<"num="<<num<<"Max="<<Max<<endl;
}
else
{
if(a>b)
{
num=a;
if(Max<=num)
Max=num;
//cout<<"Max="<<Max<<endl;
}
else
{
num=b;
if(Max<=num)
Max=num;
// cout<<"Max="<<Max<<endl;
}
}
}
}
}
//cout<<"OKOK"<<endl;
cout<<Max<<endl;
//}
return 0;
}
/*
6
7 7 7 7 7 7
6
7 8 7 7 7 8
6
7 7 8 7 7 8
6
7 3 4 1 6 7
*/


 


这篇关于C. DZY Loves Sequences的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/978403

相关文章

Learning Temporal Regularity in Video Sequences——视频序列的时间规则性学习

Learning Temporal Regularity in Video Sequences CVPR2016 无监督视频异常事件检测早期工作 摘要 由于对“有意义”的定义不明确以及场景混乱,因此在较长的视频序列中感知有意义的活动是一个具有挑战性的问题。我们通过在非常有限的监督下使用多种来源学习常规运动模式的生成模型(称为规律性)来解决此问题。体来说,我们提出了两种基于自动编码器的方法,以

【HDU】4876 ZCC loves cards 暴力

传送门:【HDU】4876 ZCC loves cards 题目分析: 这题无力吐嘈。。。。能想到的优化都用上吧。。。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define REP( i , n ) for ( int i =

【HDU】4873 ZCC Loves Intersection 数学

传送门:【HDU】4873 ZCC Loves Intersection 题目大意:给你一个D维的空间,每个维度都有一条线段平行与该维度属于的轴(如X,Y,Z轴),且线段的端点坐标取值范围0~N-1,保证左端点严格小于右端点(除该维度,其他维度的值两端点均相等)。现在告诉你每条线段的左右端点的坐标都是随机的,0~N-1随机到的概率是完全相等的!现在如果两条线段如果相交于一点,你可以获得一点

【HDU】5197 DZY Loves Orzing 【FFT启发式合并】

传送门:【HDU】5197 DZY Loves Orzing 题目分析: 首先申明,我不会 dp dp方程= =……这个东西给队友找出来了,然后我就是套这个方程做题的Qrz…… 对于这题,因为 n2 n^2个数互不相同,所以每一列都可以单独考虑。设 dpni dp_ni表示长度为 n n的排列,能恰好看见ii个人的方案数,根据队友的发现, dpni dp_ni就等于 |sni| |s_ni|

CodeForces 425C Sereja and Two Sequences

题意: 两组数字a和b  如果a[i]等于b[j]  则可将a[i]和b[j]前所有数字删掉  这种操作花费e体力  得到1元钱  或者一次删掉所有数字  这种操作花费等于曾经删除的所有数字个数  做完后得到所有钱  问 一共s体力 可以得到多少钱 思路: dp+二分 由数据可知最多拿到300元钱  因此可以定义  dp[i][j]表示有i元钱时  b串删除到了j处时  a串删到的位

Codeforces Round #FF (Div. 2/C)/Codeforces446A_DZY Loves Sequences(DP)

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'

Codeforces Round #FF (Div. 2/A)/Codeforces447A_DZY Loves Hash(哈希)

A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from

D. DZY Loves Modification

D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As we know, DZY loves playing games. One da

NLP-文本匹配-2016:Compare-Aggregate【A Compare-Aggregate Model for Matching Text Sequences】

NLP-文本匹配-2016:Compare-Aggregate【A Compare-Aggregate Model for Matching Text Sequences】

论文笔记:GEO-BLEU: Similarity Measure for Geospatial Sequences

22 sigspatial 1 intro 提出了一种空间轨迹相似性度量的方法比较了两种传统相似度度量的不足 DTW 基本特征是它完全对齐序列以进行测量,而不考虑它们之间共享的局部特征这适用于完全对齐的序列,但不适用于逐步对齐没有太多意义的序列BLEU 适用于不完全对齐的序列将序列中的地点视为单词,它们的连续组合视为地理空间𝑛-gram,应用这种方法基于局部特征评估地理空间轨迹的相似性然而,