题目链接:传送门

题目:

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. js前端文件收集(一)

    1.保存cookies的文件: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual license ...

  2. JS和Jquery获取和修改label的值

    获取值: label标签在JS和Jquery中使用不能像其他标签一样用value获取它的值: var label=document.getElementById("id");var ...

  3. Mock.js 虚拟接口 数据模拟

    Mock.js 是一款前端开发中拦截Ajax请求再生成随机数据响应的工具.可以用来模拟服务器响应. 优点是非常简单方便, 无侵入性, 基本覆盖常用的接口数据类型. 大概记录下使用过程, 详细使用可以参 ...

  4. NodeJS:(二)基础常用API

    node.js中文网:http://nodejs.cn/api/ (path.Buffer.events.fs) ①path路径-----const {resolve} = require('path ...

  5. 《Visual C# 从入门到精通》第二章方法和作用域——读书笔记

    第2章 方法和作用域 2.1创建方法 方法是一个基本的,强大的编程机制.可视为函数或者子程序相似的东西. 方法名是个有意义的标识符. 方法主体包含方法被调用时实际执行的语句. 声明一个方法的实例如下: ...

  6. wrk 压测中请求无法响应问题解决过程

    ================= 遇到问题 =================$ 直连压测 wrk -c10000 -t100 -d100m http://localhost:9981/order/ ...

  7. 2017 Russian Code Cup (RCC 17), Elimination Round D - Acute Triangles

    D - Acute Triangles 思路: 极角排序+点积叉积 在一个三角形中,如果它是直角或者顿角三角形,那么直角和顿角只会出现一次 所以直角和顿角三角形的个数等于直角和顿角的个数 所以锐角三角 ...

  8. Python自学:第三章 在列表末尾添加元素与在列表中插入元素

    motorcycles = ['honda', 'yamaha' ,'suzuki'] motorcycles.insert(0, "ducati") print(motorcyc ...

  9. Luffy之注册认证(容联云通讯短信验证)

    用户的注册认证 前端显示注册页面并调整首页头部和登陆页面的注册按钮的链接. 注册页面Register,主要是通过登录页面进行改成而成. 先构造前端页面 <template> <div ...

  10. Web 安全漏洞之 XSS 攻击

    什么是 XSS 攻击 XSS(Cross-Site Scripting)又称跨站脚本,XSS的重点不在于跨站点,而是在于脚本的执行.XSS是一种经常出现在 Web 应用程序中的计算机安全漏洞,是由于 ...