当前位置:网站首页>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;
}
边栏推荐
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- crontab定时任务
- Resthighlevelclient gets the mapping of an index
- JUC forkjoinpool branch merge framework - work theft
- Reading notes of "learn to ask questions"
- 2021 year end summary
- centos php7.2.24升级到php7.3
- EasyExcel
- 【code】if (list != null && list.size() > 0)优化,集合判空实现方式
- Journal quotidien des questions (11)
猜你喜欢

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

Software testing learning - day 3

VMware virtual machine C disk expansion

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

Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)

Golang operation redis: write and read hash type data
![[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

Operation principle of lua on C: Foundation
![[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones](/img/d0/850e095a43610366d6144b2471f3f7.jpg)
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones

EasyExcel
随机推荐
[Code] occasionally take values, judge blanks, look up tables, verify, etc
Error c2017: illegal escape sequence
Liang Ning: 30 lectures on brain map notes for growth thinking
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
JUC forkjoinpool branch merge framework - work theft
File links cannot be opened or downloaded in Google browser
Summary of the design and implementation of the weapon system similar to the paladin of vitality
2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
Laravel Web Framework
Basic teaching of crawler code
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
golang操作redis:写入、读取kv数据
How to specify the execution order for multiple global exception handling classes
Unit test notes
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
Daily question brushing record (11)
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
多个全局异常处理类,怎么规定执行顺序