题目链接:传送门

题目:

A. A Prank
time limit per test
second
memory limit per test
megabytes
input
standard input
output
standard output JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a1
, a2, ..., an of integers, such that ≤a1<a2<…<an≤ , 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] . JATC wonders what is the greatest number of elements he can erase?
Input The first line of the input contains a single integer n
(≤n≤ ) — the number of elements in the array. The second line of the input contains n
integers ai (≤a1<a2<⋯<an≤ ) — 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 .
Examples
Input
Copy Output
Copy Input
Copy Output
Copy Input
Copy Output
Copy Note In the first example, JATC can erase the third and fourth elements, leaving the array [,,_,_,,] . As you can see, there is only one way to fill in the blanks. In the second example, JATC can erase the second and the third elements. The array will become [,_,_]
. Because all the elements are less than or equal to , the array is still can be restored. Note, that he can't erase the first 2 elements. In the third example, JATC can erase the first
elements. Since all the elements are greater than or equal to , Giraffe can still restore the array. Note, that he can't erase the last 4 elements.

题目大意:

  一个长度为n(1 ≤ n ≤ 100)的,在1-1000范围内的严格递增序列a[n]。

  问最多在序列里删掉多少个元素,可以使得填回去的方法唯一(要求仍为严格递增序列)。

  比如123,就可以删掉2变成1_3,要求填进去的数比1大比3小,那么只能填2。

思路:

  直接跑一边数组,求最长的连续整数序列的长度就好了。但是要注意细节

  ①:n=1时,不能删去,答案为0。。好像有很多人fst在了这个上,据说输出了负值?。

  ②:a1 = 1,a2 = 2时,a1可以删去,而a1 = 2,a2 = 3时不能删去a1

  ③:an-1 = 999,an = 1000时,an可以删去,而an-1 = 998,an = 999时不能删去an

  对于①,初始化答案为0,不断求最大的答案就可以;

  对于②③,不妨令a[0] = 0,a[n+1] = 1001,就可以直接求最长的连续序列长度了,答案为长度-2。

代码:

#include <bits/stdc++.h>

using namespace std;
const int MAX_N = 1e2 + ; int a[MAX_N]; int main()
{
int N;
cin >> N;
for (int i = ; i <= N; i++) {
scanf("%d", a+i);
}
a[++N] = ;
int pre = ;
int len = ;
int ans = ;
for (int i = ; i <= N; i++) {
if (a[i] == pre+) {
len++;
pre++;
}
else {
ans = max(ans, len-);
len = ;
pre = a[i];
}
}
ans = max(ans, len-);
cout << ans << endl;
return ;
}

Codeforces1062A. A Prank(暴力)的更多相关文章

  1. zone.js - 暴力之美

    在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...

  2. [bzoj3123][sdoi2013森林] (树上主席树+lca+并查集启发式合并+暴力重构森林)

    Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...

  3. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  4. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  5. fragment+viepager 的简单暴力的切换方式

    这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...

  6. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  7. uoj98未来程序改 纯暴力不要想了

    暴力模拟A了,数据还是良(shui)心(shui)的 90分的地方卡了半天最后发现一个局部变量被我手抖写到全局去了,,, 心碎*∞ 没什么好解释的,其实只要写完表达式求值(带函数和变量的),然后处理一 ...

  8. 开源服务专题之------ssh防止暴力破解及fail2ban的使用方法

    15年出现的JAVA反序列化漏洞,另一个是redis配置不当导致机器入侵.只要redis是用root启动的并且未授权的话,就可以通过set方式直接写入一个authorized_keys到系统的/roo ...

  9. 关于csrss.exe和winlogon.exe进程多、占用CPU高的解决办法,有人在暴力破解

    关于csrss.exe和winlogon.exe进程多.占用CPU高的解决办法 最近VPS的CPU一直处在100%左右,后台管理上去经常打不开,后来发现上远程都要好半天才反映过来,看到任务管理器有多个 ...

随机推荐

  1. postman+linux+pistache的http通信过程

    一.pistache配置 1.安装cmake[https://www.cnblogs.com/judes/p/10327638.html] 2.下载pistache[git:https://githu ...

  2. windows10下安装Redis

    已有64位的Redis-x64-3.2.100.msi,点击以安装

  3. node服务的安装以及vue的安装

    相信很多朋友都在装node服务和安装vue的时候会遇到一些问题,下面为大家详细介绍node服务的安装以及vue的安装: 1.nodeJs官网下载版本(根据自己电脑的配置进行相应下载即可):默认安装路径 ...

  4. Lintcode12-Min Stack-Easy

    2. Min Stack Implement a stack with following functions: push(val) push val into the stack pop() pop ...

  5. 微信小程序之 真机键盘弹窗遮盖input框

    正常效果: 问题效果: 发现这个问题后呢,我先去看了api,api上是这么说的 哦吼~ 然后我也不知道是不是我的打开方式不对还是什么~~ 没有效果~~  那怎么办呢~~  换方法呗~~ 我只好用这个方 ...

  6. 三层实现办公用品表CRUD(全过程)-ASP

    好久都没有写写技术博客了,自己最近几个月都要忙着搬家还有添置家当,所以一些博客就很少去写了,天道酬勤,有些吃饭的家伙还是不能有所懈怠,所以送上一个花了几小时给人事同事写的简单办公用品表的CRUD,希望 ...

  7. python 字典与json的区别

    json:是一种数据格式,是纯字符串.可以被解析成Python的dict或者其他形式. dict:是一个完整的数据结构,是对Hash Table这一数据结构的一种实现,是一套从存储到提取都封装好了的方 ...

  8. MVC强类型视图,详细信息展示【五】

    一.在MVC三种讲到两种后端发送数据到前端的方法,今天讲的是第三种,发送过去的方法 [强类型视图]. 1. 强类型视图,就是指在传递的过程中只能传递一种类型的数据到该视图中,就比如默认的传递的数据类型 ...

  9. excel加密文件破解代码

    1. AIT+F11  2. 代码   3. F5 Public Sub AllInternalPasswords()' Breaks worksheet and workbook structure ...

  10. 环境准备——之Jdk安装

    JDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK),没有JDK的话,无法编译Java程序(指java源码.java文件),如果想只运行Java程序(指cl ...