当前位置:网站首页>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;
}
边栏推荐
- Advanced API (character stream & net for beginners)
- golang操作redis:写入、读取kv数据
- Application scenarios of Catalan number
- instanceof
- How to specify the execution order for multiple global exception handling classes
- “百度杯”CTF比赛 2017 二月场,Web:爆破-1
- 10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
- Selenium key knowledge explanation
- Advanced API (batch image Download & socket dialog)
- JMeter JSON extractor extracts two parameters at the same time
猜你喜欢
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
How to specify the execution order for multiple global exception handling classes
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Basic components and intermediate components
Practical plug-ins in idea
Inno setup production and installation package
691. 立方体IV
HMS core helps baby bus show high-quality children's digital content to global developers
Personally design a highly concurrent seckill system
Specified interval inversion in the linked list
随机推荐
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
MySQL syntax (basic)
RestHighLevelClient获取某个索引的mapping
10000小時定律不會讓你成為編程大師,但至少是個好的起點
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
Summary of the design and implementation of the weapon system similar to the paladin of vitality
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
Resttemplate configuration use
Upgrade CentOS php7.2.24 to php7.3
JS date comparison
Use of framework
Interfaces and related concepts
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
EasyExcel
Abstract learning
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
Unit test notes
服务器如何设置多界面和装IIS呢?甜甜给你解答!
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
How does the insurance company check hypertension?