Hdu-5328 Problem Killer
2016-05-28 20:15
288 查看
[align=left]Problem Description[/align]
You are a "Problem Killer", you want to solve many problems.
Now you have n
problems, the i-th
problem's difficulty is represented by an integer
ai
(1≤ai≤109).
For some strange reason, you must choose some integer
l
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
[align=left]Input[/align]
The first line contains a single integer
T,
indicating the number of cases.
For each test case, the first line contains a single integer
n,
the second line contains n
integers a1,a2,⋯,an.
T≤104,∑n≤106
[align=left]Output[/align]
For each test case, output one line with a single integer, representing the answer.
[align=left]Sample Input[/align]
2
5
1 2 3 4 6
10
1 1 1 1 1 1 2 3 4 5
[align=left]Sample Output[/align]
4
6
[align=left]Author[/align]
XJZX
[align=left]Source[/align]
2015 Multi-University Training Contest 4
[align=left]Recommend[/align]
wange2014 | We have carefully selected several similar problems for you: 5701 5700 5699 5698 5697
分析:我的写法挺容易写错的,循环中间break的情况要特殊注意边界。
You are a "Problem Killer", you want to solve many problems.
Now you have n
problems, the i-th
problem's difficulty is represented by an integer
ai
(1≤ai≤109).
For some strange reason, you must choose some integer
l
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
[align=left]Input[/align]
The first line contains a single integer
T,
indicating the number of cases.
For each test case, the first line contains a single integer
n,
the second line contains n
integers a1,a2,⋯,an.
T≤104,∑n≤106
[align=left]Output[/align]
For each test case, output one line with a single integer, representing the answer.
[align=left]Sample Input[/align]
2
5
1 2 3 4 6
10
1 1 1 1 1 1 2 3 4 5
[align=left]Sample Output[/align]
4
6
[align=left]Author[/align]
XJZX
[align=left]Source[/align]
2015 Multi-University Training Contest 4
[align=left]Recommend[/align]
wange2014 | We have carefully selected several similar problems for you: 5701 5700 5699 5698 5697
分析:我的写法挺容易写错的,循环中间break的情况要特殊注意边界。
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int t,n; double a[1000006]; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i = 1;i <= n;i++) scanf("%lf",&a[i]); int s = 1,ans = 1; while(s < n) { double d = a[s+1] - a[s]; int i = s+1; for(;i <= n;i++) if(a[i] - a[i-1] != d) break; if(i > n) i--; if(a[i] - a[i-1] != d) i--; ans = max(ans,i-s+1); s = i; } s = 1; while(s < n) { double q = a[s+1]/a[s]; int i = s+1; for(;i <= n;i++) if(a[i]/a[i-1] != q) break; if(i > n) i--; if(a[i]/a[i-1] != q) i--; ans = max(ans,i-s+1); s = i; } printf("%d\n",ans); } }
相关文章推荐
- C语言链表常见用法
- ceph翻译 Ceph: A Scalable, High-Performance Distributed File System
- 使用WinDbg —— .NET篇 (七)
- 第一章 微服务架构实践
- 个人课程总结
- 学习进度条(第十三周)
- linux下的source命令与./区别
- androidstudio app:transformClassesWithDexForDebug问题解决
- Timespec :struct type Error c2011
- Eclipse和PyDev搭建完美Python开发环境
- Clion freopen
- nyoj 710 第六届河南省大学生程序设计竞赛B
- iphone访问限制密码忘记了怎么办
- python web framework
- os.execl() VS os.system()
- 第二期冲刺站立会议个人博客4(2016/5/28)
- HDU "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场 Combine String
- 多维数组应该注意的几点
- AdaBoost算法简介
- leetcode-ZigZag Conversion-6