题目链接:传送门

题目:

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. hadoop MR的一些文件归属(包括临时文件存储情况)

    https://blog.csdn.net/bxyz1203/article/details/8057810

  2. 王之泰201771010131《面向对象程序设计(java)》第四周学习总结

    王之泰201771010131<面向对象程序设计(java)>第四周学习总结 第一部分:理论知识学习部分 第四章 1.类与对象的基础概念. a.类(class)是构造对象的模板或蓝图.由类 ...

  3. tp未验证内容-9

    在tp的数据库配置中, convention.php中所有的选项都没有设置,要自己在Home/conf/config.php中自己设置, 注意几个地方,一是数据库的名字是: db_name,不是db_ ...

  4. strcpy函数解析

    char * strcpy( char *strDest, const char *strSrc ) { assert((strDest != NULL)&&(strSrc != NU ...

  5. 将nginx添加至service服务

    一.问题描述: 无法用service命令启动nginx 二.问题分析: /etc/init.d/目录下缺少nginx默认启动脚本 三.问题解决: 在/etc/init.d/路径下添加脚本文件,名称为n ...

  6. js Infinity 属性

    Infinity 属性用于存放表示正无穷大的数值. 说明 无法使用 for/in 循环来枚举 Infinity 属性,也不能用 delete 运算符来删除它. Infinity 不是常量,可以把它设置 ...

  7. Font Awesome字体图标的 用法, 很简单

    http://fontawesome.dashgame.com/ 上面是 官网,  可下载,也可以CDN. 1...  加载 2...  用法

  8. php格式化json字符串

    header('content-type:application/json;charset=utf8'); $arr = array( 'status' => true, 'errMsg' =& ...

  9. springboot启动配置原理之三(事件监听机制)

    ApplicationContextInitializer public class HelloApplicationContextInitializer implements Application ...

  10. ceph crush的问题

    ceph crush的问题看一遍忘一遍,现将<ceph源码分析>一书中相关章节摘抄如下: 4.2.1 层级化的Cluster Map例4-1 Cluster Map定义层级化的Cluste ...