当前位置:网站首页>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)
- 熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?
- [Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
- 2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
- UTC时间、GMT时间、CST时间
- Redis command
- Resthighlevelclient gets the mapping of an index
- Practical plug-ins in idea
- Software testing learning - day one
- Integration test practice (1) theoretical basis
猜你喜欢

dataworks自定義函數開發環境搭建

POI excel percentage

Inno setup production and installation package

这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意

JMeter test result output

My 2020 summary "don't love the past, indulge in moving forward"

每日刷題記錄 (十一)
![[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones](/img/d0/850e095a43610366d6144b2471f3f7.jpg)
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones

【类和对象】深入浅出类和对象

The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
随机推荐
Understand software testing
Upgrade CentOS php7.2.24 to php7.3
Software testing assignment - day 3
Pits encountered in the use of El checkbox group
How to migrate or replicate VMware virtual machine systems
如何迁移或复制VMware虚拟机系统
Class and object summary
Search engine Bing Bing advanced search skills
【code】if (list != null && list.size() > 0)优化,集合判空实现方式
每日刷题记录 (十一)
Stream stream
Journal quotidien des questions (11)
These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
Error c2017: illegal escape sequence
Basic teaching of crawler code
Modify MySQL password
[Code] occasionally take values, judge blanks, look up tables, verify, etc
Advanced API (character stream & net for beginners)
Inno Setup 制作安装包
Asynchronous programming: async/await in asp Net