当前位置:网站首页>3311. Longest arithmetic
3311. Longest arithmetic
2022-07-03 07:03:00 【Ray. C.L】

Ideas : Enumerate each location , Set a starting point i Then find the last position of his arithmetic sequence j, We can find that at this time i——j The sequence length at any position in is less than i Start , Then we can go directly from j Position start enumeration
Code :
#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;
}
边栏推荐
- Software testing assignment - day 3
- MySQL installation
- 2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- 机械观和系统观的科学思维方式各有什么特点和作用
- Redis command
- Journal quotidien des questions (11)
- Understand software testing
- The essence of interview
- Class and object summary
猜你喜欢

如何迁移或复制VMware虚拟机系统

Application scenarios of Catalan number

2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution

Pytest -- write and manage test cases

Personally design a highly concurrent seckill system
![[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)](/img/7f/3d6b6ea5319f7165e07baf0a78d318.jpg)
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)

Selenium key knowledge explanation

Summary of UI module design and practical application of agent mode

每日刷题记录 (十一)

Flask Foundation
随机推荐
Strategy mode
2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
Pits encountered in the use of El checkbox group
[attribute comparison] defer and async
Summary of remote connection of MySQL
instanceof
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
On the practice of performance optimization and stability guarantee
保险公司怎么查高血压?
Journal quotidien des questions (11)
centos php7.2.24升级到php7.3
10000小时定律不会让你成为编程大师,但至少是个好的起点
PHP install composer
Distributed ID
EasyExcel
Redis command
Pytest -- write and manage test cases
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
Golang operation redis: write and read hash type data