Arithmetic Progression超时了n次,终于过了!
来源:互联网 发布:淘宝购物退款退到哪里 编辑:程序博客网 时间:2024/04/28 07:55
Arithmetic Progression
题目描述
“In mathematics, an arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, … is an arithmetic progression with common difference of 2.”
- Wikipedia
This is a quite simple problem, give you the sequence, you are supposed to find the length of the longest consecutive subsequence which is an arithmetic progression.
输入格式
There are several test cases. For each case there are two lines. The first line contains an integer number N (1 <= N <= 100000) indicating the number of the sequence. The following line describes the N integer numbers indicating the sequence, each number will fit in a 32bit signed integer.
输出
For each case, please output the answer in one line.
样例输入
6
1 4 7 9 11 14
样例输出
3
代码:
#include<stdio.h>
#define N 100005int a[100001];
int max(int x,int y){
return(x>y?x:y);
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int m=1,j=0,k,s;
while(j<n-1)
{
k=j+1;
s=a[k] - a[j];
while(k<n&&(a[k]-a[k-1])==s)
k++;
k--;
m=max(m, k-j+1);
j=k;
}
printf("%d\n",m);
}
return 0;
}
- Arithmetic Progression超时了n次,终于过了!
- N 次跳票后,Fedora 27 正式版终于发布了
- 软件设计师终于过了
- 终于过17:00了~~~~~~
- 终于过完年了
- 终于过四级了!
- 终于过了科目二
- 编码考试终于过了。
- NYOJ终于过百了
- 终于过了3天了
- poj2424(一周了,终于过了!)
- ARITHMETIC PROGRESSION
- Arithmetic Progression
- Arithmetic Progression
- Arithmetic Progression
- 三天终于过了,终于可以写文章了。呵呵
- sublime text3安装emmet插件及PyV8:小白重试了n次后终于成功
- 第n次学习后我终于对正则明白了一点点
- Matlab命令(部分)
- 用户权限管理
- 关于ISR中清除中断源的问题
- 查找
- WinDbg配置和使用基础
- Arithmetic Progression超时了n次,终于过了!
- Silverlight WCF RIA服务(十五)数据 5
- 说说J2EE、J2SE、J2ME的区别?
- 华为HG556a路由器刷写OpenWrt
- C语言种指针难点(1)
- Top 10 Java Debugging Tips with Eclipse(Eclipse调试Java的10个技巧)
- 关于金山软件杀毒软件卸载后Kingsoft大文件无法删除的问题
- 内核数据结构之队列-kfifo
- 设置IE版本以支持不兼容IE高版本的应用