当前位置:网站首页>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;
}
边栏推荐
- Winter vacation work of software engineering practice
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
- RestHighLevelClient获取某个索引的mapping
- Daily question brushing record (11)
- mongodb
- Laravel框架 踩坑(一)
- 10000小時定律不會讓你成為編程大師,但至少是個好的起點
- Pytest -- write and manage test cases
- Flask Foundation
- Abstract learning
猜你喜欢

EasyExcel

Mise en place d'un environnement de développement de fonctions personnalisées

These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products

2022年华东师范大学计科考研复试机试题-详细题解

New knowledge! The virtual machine network card causes your DNS resolution to slow down

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

Personally design a highly concurrent seckill system

Jenkins

Software testing learning - day 3

Dbnet: real time scene text detection with differentiable binarization
随机推荐
Golang operation redis: write and read kV 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
Distributed transactions
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
如何迁移或复制VMware虚拟机系统
Shim and Polyfill in [concept collection]
深度学习参数初始化(一)Xavier初始化 含代码
VMware virtual machine C disk expansion
php artisan
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
Tool class static method calls @autowired injected service
萬卷書 - 價值投資者指南 [The Education of a Value Investor]
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
Know flex box
Centos切换安装mysql5.7和mysql8.0
These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
Application scenarios of Catalan number
centos php7.3安装redis扩展
HMS core helps baby bus show high-quality children's digital content to global developers