HDU5328-Problem Killer
来源:互联网 发布:淘宝怎么联系不了卖家 编辑:程序博客网 时间:2024/05/21 18:38
Problem Killer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2795 Accepted Submission(s): 964
Problem Description
You are a "Problem Killer", you want to solve many problems.
Now you haven problems, the i -th problem's difficulty is represented by an integer ai (1≤ai≤109 ).
For some strange reason, you must choose some integerl and r (1≤l≤r≤n ), and solve the problems between the l -th and the r -th, and these problems' difficulties must form an AP (Arithmetic Progression) or a GP (Geometric Progression).
So how many problems can you solve at most?
You can find the definitions of AP and GP by the following links:
https://en.wikipedia.org/wiki/Arithmetic_progression
https://en.wikipedia.org/wiki/Geometric_progression
Now you have
For some strange reason, you must choose some integer
So how many problems can you solve at most?
You can find the definitions of AP and GP by the following links:
https://en.wikipedia.org/wiki/Arithmetic_progression
https://en.wikipedia.org/wiki/Geometric_progression
Input
The first line contains a single integer T , indicating the number of cases.
For each test case, the first line contains a single integern , the second line contains n integers a1,a2,⋯,an .
T≤104,∑n≤106
For each test case, the first line contains a single integer
Output
For each test case, output one line with a single integer, representing the answer.
Sample Input
251 2 3 4 6101 1 1 1 1 1 2 3 4 5
Sample Output
46
Author
XJZX
Source
2015 Multi-University Training Contest 4
Recommend
wange2014
题意:给你n个数,求等比或者等差数列中最长的区间的长度
解题思路:处理出公差和公比序列,然后用尺取法求解
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int n,a[1000009],b[1000009];double c[1000009];int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(i>1) { b[i]=a[i]-a[i-1]; c[i]=1.0*a[i]/a[i-1]; } } int head=1,rear=1,ma=1; while(rear<n) { rear++; while(b[head+1]!=b[rear]&&rear>head) head++; ma=max(ma,rear-head+1); } head=1,rear=2; while(rear<n) { rear++; while(c[head+1]!=c[rear]&&rear>head) head++; ma=max(ma,rear-head+1); } printf("%d\n",ma); } return 0;}
阅读全文
0 0
- HDU5328.Problem Killer
- hdu5328 Problem Killer
- hdu5328 Problem Killer(dp)
- HDU5328-Problem Killer
- 解题报告 之 HDU5328 Problem Killer
- 解题报告 之 HDU5328 Problem Killer
- 2015年多校联合训练第四场(Problem Killer)hdu5328
- hdu5328
- uva 11898 - Killer Problem
- UVA - 11898 Killer Problem
- UVA11898 - Killer Problem(暴力)
- HDU 5328 Problem Killer
- 【HDOJ 5328】 Problem Killer
- HDU 5328 Problem Killer
- hdu 5328 Problem Killer
- hdu 5328 Problem Killer
- HDU 5238 Problem Killer
- HDU 5328 Problem Killer
- JavaScript基础(4)之location
- MFC使用ODBC连接MySQL数据库
- 随想| Continue
- 2017年上海金马五校程序设计竞赛(网上资格赛)J : Raising Bacteria
- java中堆和栈内存的区别
- HDU5328-Problem Killer
- Hello World MyCSDN
- Java基础之线程
- Eclipse 自动格式化代码的几种方法
- Java中常量写到接口中还是类中
- logistic回归
- 浮点数在内存中的表示移位存储难点的理解
- TensorFlow使用PyCharm编辑器进行配置和编译在Windows下
- 集合知识点归纳