A. A Prank

time limit per test   1 second
memory limit per test    256 megabytes

题目链接https://codeforc.es/contest/1062/problem/A

Description:

JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a1, a2, ..., anan of integers, such that 1≤a1<a2<…<an≤1031≤a1<a2<…<an≤103, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range [1,103][1,103].

JATC wonders what is the greatest number of elements he can erase?

Input:

The first line of the input contains a single integer nn (1≤n≤100,1≤n≤100) — the number of elements in the array.

The second line of the input contains nn integers aiai (1≤a1<a2<⋯<an≤103,1≤a1<a2<⋯<an≤103) — the array written by Giraffe.

Output:

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print 0.

Sample Input:

6
1 3 4 5 6 9

Sample Output:

2

题意:

给出一个严格递增的数组,问有连续的多少个数在数组里面的位置是可以确定的。

题解:

通过模拟发现当ai - ai-1 = ai+1 - ai = 1时,位置时可以被确定的,然后模拟一下就好了。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std; const int N = ;
int a[N],d[N];
int n,ans=; int main(){
scanf("%d",&n);
a[n+]=;
for(int i=;i<=n;i++) scanf("%d",&a[i]) , d[i]=a[i]-a[i-];
d[n+]=a[n+]-a[n];
int cnt = ;
for(int i=;i<=n+;i++){
if(d[i]==d[i-] &&d[i]==){
cnt++;
}else{
ans=max(ans,cnt);
cnt=;
}
}
printf("%d",max(ans,cnt));
return ;
}

Codeforces Round #520 (Div. 2) A. A Prank的更多相关文章

  1. Codeforces Round #520 (Div. 2)

    Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> u ...

  2. Codeforces Round #520 (Div. 2) E. Company(dfs序判断v是否在u的子树里+lca+线段树)

    https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次 ...

  3. Codeforces Round #520 (Div. 2) Solution

    A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...

  4. Codeforces Round #520 (Div. 2) B. Math 唯一分解定理+贪心

    题意:给出一个x 可以做两种操作  ①sqrt(x)  注意必须是完全平方数  ② x*=k  (k为任意数)  问能达到的最小的x是多少 思路: 由题意以及 操作  应该联想到唯一分解定理   经过 ...

  5. CF每日一练 Codeforces Round #520 (Div. 2)

    比赛过程总结:过程中有事就玩手机了,后面打的状态不是很好,A题理解错题意,表明了内心不在状态,B题想法和思路都是完全正确的,但是并没有写出来,因为自己代码能力不强,思路不是特别清晰,把代码后面写乱了, ...

  6. Codeforces Round #520 (Div. 2) D. Fun with Integers

    D. Fun with Integers 题目链接:https://codeforc.es/contest/1062/problem/D 题意: 给定一个n,对于任意2<=|a|,|b|< ...

  7. Codeforces Round #520 (Div. 2) C. Banh-mi

    C. Banh-mi time limit per test:1 second memory limit per test:256 megabytes 题目链接:https://codeforc.es ...

  8. Codeforces Round #520 (Div. 2) B. Math

    B. Math time limit per test:1 second memory limit per test:256 megabytes Description: JATC's math te ...

  9. Codeforces Round #520 (Div. 2) B math(素数因子的应用)

    题意: 给出一个n ; 有两个操作: 1,mul A   ,   n=n*A   : 2,sqrt()  ,  n=sqrt(n)  开更出来必须是整数 : 求出经过这些操作后得出的最小  n , 和 ...

随机推荐

  1. python中一些内置函数实例

    lambda表达式 简单函数可用lambda表达式 1. def f1() return(123) r1=f1() print() 2. f2=lambda:123 r2=f2() print() 以 ...

  2. 博弈dp 以I Love this Game! POJ - 1678 为例

    写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...

  3. STL 一些常用的STL函数(持续更新

    先说一下  一边要用到算法的东西一般要加#include<algorithm>头文件 一.栈和队列 1 栈 :一种线性表 特点  后进先出 头文件  #include<stack&g ...

  4. 详解 RPL、DPL、CPL 的关系

    保护模式中最重要的一个思想就是通过分级把代码隔离了起来,不同的代码在不同的级别,使大多数情况下都只和同级代码发生关系.Intel的80286以上的cpu可以识別4个特权级(或特权层) ,0级到3级.数 ...

  5. MySQL 从入门到删库

    基本操作 登陆指令 mysql -u用户名 -p密码(可以非明文输入) -h主机/IP -D端口 --prompt 提示符 修改提示符 \D 日期 \d 当前数据库 \h 服务器名 \u 用户名 // ...

  6. @Transactional spring 事务失效(转载)

    原文地址:http://hwak.iteye.com/blog/1611970 1. 在需要事务管理的地方加@Transactional 注解.@Transactional 注解可以被应用于接口定义和 ...

  7. Django admin操作

      无名小妖     昵称:无名小妖园龄:1年6个月粉丝:22关注:1 +加关注 搜索     常用链接 我的随笔 我的评论 我的参与 最新评论 我的标签 我的标签 Python(1) python3 ...

  8. SpringBoot学习:IDEA中快速搭建springboot项目

    项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821 (一)IDEA中创建maven web项目 创建好项目后设置项目的编译路径: (二)引入 ...

  9. SGU刷题之路,开始了

    0. 关于SGU的简介 SGU的网址是:acm.sgu.ru 向不了解的同学介绍一下SGU这个题库: 1. 题目难度很高,题目大多很经典. 2. 其数据范围很小,时间和空间要求也都很小,同时很精确.甚 ...

  10. C#调用C++编写的dll

    界面还是C#写的方便点,主要是有一个可视化的编辑器,不想画太多的时间在界面上.但是自己又对C++了解的多一些,所以在需要一个良好的界面的情况下,使用C++来写代码逻辑,将其编译成一个dll,然后用C# ...