Codeforces Round #520 (Div. 2) A. A Prank
A. A Prank
题目链接: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的更多相关文章
- Codeforces Round #520 (Div. 2)
Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> u ...
- Codeforces Round #520 (Div. 2) E. Company(dfs序判断v是否在u的子树里+lca+线段树)
https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次 ...
- Codeforces Round #520 (Div. 2) Solution
A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...
- Codeforces Round #520 (Div. 2) B. Math 唯一分解定理+贪心
题意:给出一个x 可以做两种操作 ①sqrt(x) 注意必须是完全平方数 ② x*=k (k为任意数) 问能达到的最小的x是多少 思路: 由题意以及 操作 应该联想到唯一分解定理 经过 ...
- CF每日一练 Codeforces Round #520 (Div. 2)
比赛过程总结:过程中有事就玩手机了,后面打的状态不是很好,A题理解错题意,表明了内心不在状态,B题想法和思路都是完全正确的,但是并没有写出来,因为自己代码能力不强,思路不是特别清晰,把代码后面写乱了, ...
- Codeforces Round #520 (Div. 2) D. Fun with Integers
D. Fun with Integers 题目链接:https://codeforc.es/contest/1062/problem/D 题意: 给定一个n,对于任意2<=|a|,|b|< ...
- 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 ...
- 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 ...
- Codeforces Round #520 (Div. 2) B math(素数因子的应用)
题意: 给出一个n ; 有两个操作: 1,mul A , n=n*A : 2,sqrt() , n=sqrt(n) 开更出来必须是整数 : 求出经过这些操作后得出的最小 n , 和 ...
随机推荐
- python基础数据类型的相关知识点
1.字符串的函数join >>> s = "Hello" >>> s1 = s.join("你好")#将字符串Hello插入 ...
- R语言绘图:雷达图
使用fmsb包绘制雷达图 library("fmsb") radarfig <- rbind(rep(90, 4), rep(60, 4), c(86.17, 73.96, ...
- SKIP(插入空行)
WRITE 'This is the 1st line'. SKIP. WRITE 'This is the 2nd line'. 跳转至某一行 SKIP TO LINE line_number. 插 ...
- JS 实现随机验证码功能
1.验证码 验证是网页常出现的一个验证点,所谓验证码类型有很多,下面代码只是实现一个简单的验证功能. <div> <input type = "text" id ...
- oracle杀死锁表的进程(转发+合并+自己实践)
之一: Oracle数据库操作中,我们有时会用到锁表查询以及解锁和kill进程等操作 (1)锁表查询的代码有以下的形式:select count(*) from v$locked_object;sel ...
- linux 操作之一 如何在linux将本地数据*.sql文件导入到linux 云服务器上的mysql数据库
liunx 版本ubuntu 16.4 mysql 版本 5.6 1)准备*.sql文件 (* 是准备导入的sql文件的名字) 2)liunx 远程客户端 SecureCRT 7.0 alt+p ...
- L009文件属性知识详解小节
本堂课分为5部分内容 1.linux下重要目录详解 2.PATH变量路径内容 3.linux系统中文件类型介绍 4.linux系统中文件属性详细介绍 5.linux系统文件属性inode与block知 ...
- 【数据库】 SQLite 语法
[数据库] SQLite 语法 一 . 创建数据库 1. 只需创建数据库,只需创建文件,操作时将连接字符串指向该文件即可 2. 连接字符串 : data source = FilePath; 不能加密 ...
- React切换显示和隐藏
1 {radioChange >= 0 && 2 <div> 3 {radioChange === 0 ? ( 4 <div className={style. ...
- 深度可分卷积(Depthwise Separable Conv.)计算量分析
上次读到深度可分卷积还是去年暑假,各种细节都有些忘了.记录一下,特别是计算量的分析过程. 1. 标准卷积和深度可分卷积 标准卷积(MobileNet论文中称为Standard Convolution, ...