Codeforces1062A. A Prank(暴力)
题目链接:传送门
题目:
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(暴力)的更多相关文章
- zone.js - 暴力之美
在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...
- [bzoj3123][sdoi2013森林] (树上主席树+lca+并查集启发式合并+暴力重构森林)
Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- fragment+viepager 的简单暴力的切换方式
这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...
- 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 ...
- uoj98未来程序改 纯暴力不要想了
暴力模拟A了,数据还是良(shui)心(shui)的 90分的地方卡了半天最后发现一个局部变量被我手抖写到全局去了,,, 心碎*∞ 没什么好解释的,其实只要写完表达式求值(带函数和变量的),然后处理一 ...
- 开源服务专题之------ssh防止暴力破解及fail2ban的使用方法
15年出现的JAVA反序列化漏洞,另一个是redis配置不当导致机器入侵.只要redis是用root启动的并且未授权的话,就可以通过set方式直接写入一个authorized_keys到系统的/roo ...
- 关于csrss.exe和winlogon.exe进程多、占用CPU高的解决办法,有人在暴力破解
关于csrss.exe和winlogon.exe进程多.占用CPU高的解决办法 最近VPS的CPU一直处在100%左右,后台管理上去经常打不开,后来发现上远程都要好半天才反映过来,看到任务管理器有多个 ...
随机推荐
- Bootstrap3基础 table-condensed 表格中的单元格紧凑一些
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- Python3 tkinter基础 Menubutton 点击按钮出现下拉菜单
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Anaconda环境下安装库
使用anaconda环境下使用pycharm后,有些其他库也想安装,但开始在python.exe目录下安装没成功,因为pycharm用的环境已经不是原始的python.exe解释器了.就总结了一些安装 ...
- 使用python+hadoop-streaming编写hadoop处理程序
Hadoop Streaming提供了一个便于进行MapReduce编程的工具包,使用它可以基于一些可执行命令.脚本语言或其他编程语言来实现Mapper和 Reducer,从而充分利用Hadoop并行 ...
- 自己封装myLocalStorage,使其有有效期
项目中遇见 cookie 值存不上,what fuck?什么情况,不知道.用$.cookie 和原生的 cookie 都不行,存上值,就被删了一样.找不见地方.考虑到项目比较大,去找得代价,还不如换种 ...
- 算法笔记--极大极小搜索及alpha-beta剪枝
参考1:https://www.zhihu.com/question/27221568 参考2:https://blog.csdn.net/hzk_cpp/article/details/792757 ...
- webapi研究说明
首先定义公共的返回对象 /// <summary> /// 返回数据对象 /// </summary> public class ResponseItem<T> { ...
- Django 模板继承
本质上来说,模板继承就是先构造一个基础框架模板,而后在其子模板中对它所包含站点公用部分和定义块进行重载. 让我们通过修改 current_datetime.html 文件,为 current_date ...
- oracle数据库 concat 与 ||
1.简述: 通过几条sql语句来引入此问题 先新建一张表,插入几条数据,如下: CREATE TABLE tab1 (col1 VARCHAR2(6), col2 CHAR(6), col3 VARC ...
- Practical Node.js (2018版) 13章, Node HTTP/2 Servers
新增的章节. If you are not using HTTP/2, then you are losing out on big improvements. HTTP/2相比http/1有很大的区 ...