当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Journal quotidien des questions (11)
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
Liang Ning: 30 lectures on brain map notes for growth thinking
JMeter test result output
深度学习参数初始化(一)Xavier初始化 含代码
DBNet:具有可微分二值化的实时场景文本检测
[classes and objects] explain classes and objects in simple terms
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
Flask Foundation
随机推荐
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
DBNet:具有可微分二值化的实时场景文本检测
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
My 2020 summary "don't love the past, indulge in moving forward"
Pits encountered in the use of El checkbox group
The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?
Class and object summary
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
POI excel percentage
Search engine Bing Bing advanced search skills
Modify MySQL password
Tool class static method calls @autowired injected service
Crontab scheduled task
How does the insurance company check hypertension?
mongodb
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
Journal quotidien des questions (11)
VMware virtual machine C disk expansion
MySQL mistakenly deleted the root account and failed to log in