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%左右,后台管理上去经常打不开,后来发现上远程都要好半天才反映过来,看到任务管理器有多个 ...
随机推荐
- MySQL基础和JDBC
第一章 命令行工具 mysqladmin:MySQL服务器管理工具 mysql:MySQL客服端链接工具 mysqldump 演示链接到服务器host=127.0.0.1,用户名为root,密码为空 ...
- .NET ActiveMQ类库
ActiveMQ .NET类库 ActiveMQ是一种开源的,实现了JMS规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信. 0. 准备 使用Nuget ...
- java 保存到mysql数据库中文乱码
<property name="jdbcUrl">jdbc:mysql://localhost:3306/company?useUnicode=true&cha ...
- 去除pt种里tracker的方法
1.下载BEncode Editor,打开 2.把下载的种子拖进去,可以看到这样的: tracker就是箭头指的地方,这个包含了个人帐号独一无二的私钥,如果泄露给别人的话别人下载就是走的你的帐号,轻则 ...
- redis-server 使用
redis.conf ################################## NETWORK ##################################### bind 127 ...
- Ubuntu 14 如何解压 .zip、.rar 文件
.zip 和 .rar 是Windows下常用的压缩文件,在Ubuntu中如何解压. [解压.zip文件] Ubuntu中貌似已经安装了unzip软件,解压命令如下: unzip ./FileName ...
- 【Core Swagger】.NET Core中使用swagger
一.入门 https://www.nuget.org/packages/Swashbuckle.AspNetCore.SwaggerGen/ 1.添加核心NUGET包 Swashbuckle.AspN ...
- 盛最多水的容器(java实现)
题目: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的 ...
- Spring Boot读取配置的几种方式
读取application文件 在application.yml或者properties文件中添加: info.address=USAinfo.company=Springinfo.degree=hi ...
- Python 总结一
'''形式参数不占内存,在调用时开辟内存,在函数结束时释放内存默认参数 调用方式:位置参数.关键字参数 *args (元组) **kwargs(字典) 局部变量:在子程序中使用的变量全局变量:glob ...