当前位置:网站首页>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;
}
边栏推荐
- dataworks自定義函數開發環境搭建
- Summary of the design and implementation of the weapon system similar to the paladin of vitality
- Unit test notes
- Software testing assignment - day 3
- Simple understanding of bubble sorting
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- 【code】偶尔取值、判空、查表、验证等
- Laravel frame step pit (I)
- Error c2017: illegal escape sequence
- 10000小時定律不會讓你成為編程大師,但至少是個好的起點
猜你喜欢
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
Software testing assignment - the next day
利用C#实现Pdf转图片
[set theory] partition (partition | partition example | partition and equivalence relationship)
每日刷题记录 (十一)
Summary of UI module design and practical application of agent mode
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
Use the jvisualvm tool ----- tocmat to start JMX monitoring
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
[untitled]
随机推荐
利用C#实现Pdf转图片
Troubleshooting of high CPU load but low CPU usage
Know flex box
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
2021 year end summary
Realize PDF to picture conversion with C #
10000小时定律不会让你成为编程大师,但至少是个好的起点
Distributed transactions
Shim and Polyfill in [concept collection]
Integration test practice (1) theoretical basis
Laravel框架 踩坑(一)
JS date comparison
Practical plug-ins in idea
Operation principle of lua on C: Foundation
UTC time, GMT time, CST time
HMS core helps baby bus show high-quality children's digital content to global developers
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
多个全局异常处理类,怎么规定执行顺序
Search engine Bing Bing advanced search skills
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet