CF 602B Approximating a Constant Range
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<stack>
#include<map>
using namespace std;
typedef long long ll; int main()
{
int n,a1,a,dist1=,dist2=,l=,r=,ans=;
scanf("%d",&n);
scanf("%d",&a1);
for(int i=;i<=n;i++)
{
scanf("%d",&a);
dist1=a-a1; //根据题意:差值只能为0,1,-1
a1=a; if(dist1==) continue; //差值为0的继续往前走
if(dist1!=dist2) //差值不为0且与前一个差值不相等
{
dist2=dist1; //更新当前区间的差值
r=i;
}
else //差值不为0但与前一个差值相同(如子序列1 2 3)
{
ans=max(ans,i-l); //更新区间长度
l=r;r=i;
}
}
ans=max(ans,n-l+);
//若子序列的首尾相同(如子序列2 3 3 2),则ans=n-l+1;
printf("%d\n",ans);
return ;
}
CF 602B Approximating a Constant Range的更多相关文章
- Codeforces 602B Approximating a Constant Range(想法题)
B. Approximating a Constant Range When Xellos was doing a practice course in university, he once had ...
- codeforce -602B Approximating a Constant Range(暴力)
B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 256 megabytes ...
- FZU 2016 summer train I. Approximating a Constant Range 单调队列
题目链接: 题目 I. Approximating a Constant Range time limit per test:2 seconds memory limit per test:256 m ...
- Codeforces Round #333 (Div. 2) B. Approximating a Constant Range st 二分
B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
- cf602B Approximating a Constant Range
B. Approximating a Constant Range time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Round #333 (Div. 2) B. Approximating a Constant Range
B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【CodeForces 602C】H - Approximating a Constant Range(dijk)
Description through n) and m bidirectional railways. There is also an absurdly simple road network — ...
- #333 Div2 Problem B Approximating a Constant Range(尺取法)
题目:http://codeforces.com/contest/602/problem/B 题意 :给出一个含有 n 个数的区间,要求找出一个最大的连续子区间使得这个子区间的最大值和最小值的差值不超 ...
随机推荐
- log4j基本使用方法
通过配置文件可知,我们需要配置3个方面的内容: 1.根目录(级别和目的地) 2.目的地(控制台和文件等) 3.输出样式 Log4j由三个重要的组件构成: 1.日志信息的优先级 日志信息的优先级从高到低 ...
- matlab中选择图片路径
%读取训练图片数据文件 [FileName,PathName] = uigetfile('*.*','选择测试图片数据文件t10k-images.idx3-ubyte'); %暴露图片路径 saved ...
- 敏捷开发(六)- SCRUM全员会议
本文主要是为了检测你对SCRUM 全员会议的了解和使用程度,通过本文你可以检测一下 1.你们的SCRUM 全员会议的过程和步骤 2.SCRUM 全员会议的输出结果 一.会议目的 组成团 ...
- 【AndroidStudio】关于SVN的相关配置简介
AndroidStudio 的SVN 安装和使用方法与我以前用的其他IDE 都有很大差别,感觉特麻烦,网上相关资料很少,貌似现在 Git 比较流行,之前有用过 github 但是他只能是开源项目免费, ...
- iOS根据网络图片的size大小设置UIImageView的大小
有时候在设置UIImageView的大小时候需要根据UIimage的长宽比来自动设置,不让图片原比例失真. 如果是从本地获取到的图片,[UIImage imageNamed:@"" ...
- Alamofire4.0 在 CocoaPods无法更新的问题
因为淘宝镜像已经不能使用,使用新的镜像升级ruby到最新状态 platform :ios, '9.0'use_frameworks! target '输入你的工程名字' do pod 'Alamofi ...
- UNIX基础--进程和守护进程
进程和守护进程 Processes and Daemons 进程(Processes) FreeBSD 是一个多任务操作系统. 这就意味着好像一次可以运行一个以上的程序. 每个占用一定时间运行的程序就 ...
- 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[20]; scanf ...
- css实现遮罩层,父div透明,子div不透明
使用元素的opacity 属性,设置遮罩层的效果, 主要 样式是:background-color: #ooo; opacity:0.3; <div style="width:500p ...
- Session小解
Session特点: 1.Session保存在服务器端,为了获得更高的存取速度,一般把Session保存在内存当中: 2.每个用户都有一个独立的Session,为了避免大量用户访问服务器导致内存溢出, ...