当前位置:网站首页>3311. 最长算术
3311. 最长算术
2022-07-03 07:00:00 【Ray.C.L】

思路:枚举每个位置,设定一个起点i然后找到他等差数列的最后一个位置j,我们可以发现此时i——j中的任意位置的序列长度都小于i开始,那么我们下次可以直接从j位置开始枚举
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5+5;
int w[N];
int main()
{
int T;
scanf("%d", &T);
for(int cases = 1; cases <= T; cases ++){
int n;
scanf("%d", &n);
for(int i = 0; i < n; i ++)
scanf("%d", &w[i]);
int res = 0;
for(int i = 0; i < n; i ++){
int j = i + 2;
while(j < n && w[j] - w[j - 1] == w[j - 1] - w[j - 2]) j++;
res = max(res, j -i);
i = j - 2;
}
printf("Case #%d: %d\n", cases, res);
}
return 0;
}
边栏推荐
- 萬卷書 - 價值投資者指南 [The Education of a Value Investor]
- EasyExcel
- Ruoyi interface permission verification
- File links cannot be opened or downloaded in Google browser
- Modify MySQL password
- Unittest attempt
- HMS core helps baby bus show high-quality children's digital content to global developers
- Summary of the design and implementation of the weapon system similar to the paladin of vitality
- How to plan well?
- Split small interface
猜你喜欢

利用C#实现Pdf转图片

My 2020 summary "don't love the past, indulge in moving forward"

IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库

10000小时定律不会让你成为编程大师,但至少是个好的起点

JMeter test result output

Integration test practice (1) theoretical basis

Arctic code vault contributor
![[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet](/img/9d/42dfef67246740f0dba0c6d8f1b625.jpg)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet

熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?

JMeter JSON extractor extracts two parameters at the same time
随机推荐
How does the insurance company check hypertension?
golang操作redis:写入、读取kv数据
RestHighLevelClient获取某个索引的mapping
[C /vb.net] convert PDF to svg/image, svg/image to PDF
Redis command
MySQL installation
2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
(翻译)异步编程:Async/Await在ASP.NET中的介绍
Resttemplate configuration use
The essence of interview
My 2020 summary "don't love the past, indulge in moving forward"
Class and object summary
[untitled]
Laravel Web框架
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
Use the jvisualvm tool ----- tocmat to start JMX monitoring
Realize PDF to picture conversion with C #
Search engine Bing Bing advanced search skills
Unittest attempt
Shim and Polyfill in [concept collection]