当前位置:网站首页>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;
}
边栏推荐
- 2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
- 多个全局异常处理类,怎么规定执行顺序
- 每日刷題記錄 (十一)
- JS date comparison
- [LeetCode]404. Sum of left leaves
- 2022年华东师范大学计科考研复试机试题-详细题解
- New knowledge! The virtual machine network card causes your DNS resolution to slow down
- The education of a value investor
- [LeetCode]404. 左叶子之和
- 2021 year end summary
猜你喜欢

Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record

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

Setting up the development environment of dataworks custom function

10000小时定律不会让你成为编程大师,但至少是个好的起点

Winter vacation work of software engineering practice

Software testing assignment - the next day

【无标题】

POI excel percentage

Operation principle of lua on C: Foundation

EasyExcel
随机推荐
UTC time, GMT time, CST time
(翻译)异步编程:Async/Await在ASP.NET中的介绍
golang操作redis:写入、读取kv数据
POI excel percentage
New knowledge! The virtual machine network card causes your DNS resolution to slow down
Thoughts in Starbucks
Pytest -- write and manage test cases
Practical plug-ins in idea
mongodb
Basic teaching of crawler code
Software testing learning - day 3
Laravel框架 踩坑(一)
Laravel Web Framework
多个全局异常处理类,怎么规定执行顺序
Stream stream
MySQL mistakenly deleted the root account and failed to log in
On the practice of performance optimization and stability guarantee
php安装swoole扩展
golang操作redis:写入、读取hash类型数据
Upgrade CentOS php7.2.24 to php7.3