当前位置:网站首页>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;
}
边栏推荐
- 【code】偶尔取值、判空、查表、验证等
- [LeetCode]404. 左叶子之和
- Redis command
- php artisan
- JMeter JSON extractor extracts two parameters at the same time
- Software testing assignment - day 1
- 这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
- C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
- Thoughts in Starbucks
- Practical plug-ins in idea
猜你喜欢

多个全局异常处理类,怎么规定执行顺序

JMeter JSON extractor extracts two parameters at the same time

Interfaces and related concepts

Summary of remote connection of MySQL

Notes on the core knowledge of Domain Driven Design DDD

Realize PDF to picture conversion with C #

On the practice of performance optimization and stability guarantee

golang操作redis:写入、读取hash类型数据

Reading notes of "learn to ask questions"

Journal quotidien des questions (11)
随机推荐
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
File links cannot be opened or downloaded in Google browser
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
php安装swoole扩展
Golang operation redis: write and read hash type data
深度学习参数初始化(一)Xavier初始化 含代码
10000小時定律不會讓你成為編程大師,但至少是個好的起點
Laravel Web Framework
Distributed lock
EasyExcel
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
Selenium key knowledge explanation
[LeetCode]404. 左叶子之和
Thoughts on project development
Unit test notes
MySQL transaction rollback, error points record
【code】偶尔取值、判空、查表、验证等
Software testing learning - day one
Resthighlevelclient gets the mapping of an index