Problem J: Arithmetic Sequence——华中农业大学第四届程序设计大赛网络同步赛题目
2016-05-15 15:13
399 查看
Problem J: Arithmetic Sequence
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1771 Solved: 299
[Submit][Status][Web
Board]
Description
Giving a number sequence A withlength n, you should choosing m numbers from A(ignore
the order) which can form an arithmetic sequence and make m as large as possible.
Input
There are multiple test cases. In each test case, the first line contains a positiveinteger n. The second line contains n integers separated by spaces, indicating the number
sequence A. All the integers are positive and not more than 2000. The input will end by EOF.
Output
For each test case, output the maximum asthe answer in one line.
Sample Input
5 1 3 5 7 10 8 4 2 7 11 3 1 9 5
Sample Output
4 6
HINT
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,a[2005],b[2005],i,j,t,max,len,maxx,minx; while(scanf("%d",&n)!=EOF) { max=0; maxx=0; minx=999999; memset(b,0,sizeof(b)); memset(a,0,sizeof(a)); for(i=0;i<n;i++) { scanf("%d",&a[i]); b[a[i]]++; if(maxx<a[i]) maxx=a[i]; if(minx>a[i]) minx=a[i]; } for(i=0;i<n;i++)//从第一个到最后一个为开头的数列 { if(max<b[a[i]]) max=b[a[i]];//公差为0的数列 for(j=1;j<=maxx-minx;j++)//数列长度 { len=1; t=a[i]; while(1) { t+=j; if(b[t]==0||t>maxx) break; len++; } if(max<len) max=len; } } printf("%d\n",max); } return 0; }
相关文章推荐
- 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列
- 使用nodejs的net模块创建TCP服务器
- 华中农业大学第四届程序设计大赛网络同步赛题目
- 【网络】NAT与代理服务器
- tcp/ip basics
- WIN10 VBOX UBUNTU 网络访问不了
- 如何使用XMLHTTPRequest对象实现无刷新效果
- TCP/IP协议之链路层
- 使用nodejs的http模块创建web服务器
- http statusCode(状态码) 200、300、400、500序列
- ubuntu 14 系统的网络服务与此版本的网络管理器不兼容
- Tensorflow MNIST浅层神经网络的解释和答复
- Tensorflow MNIST浅层神经网络的解释和答复
- TCPDUMP(命令行操作)-抓包、筛选、高级筛选、过程文档记录
- GuiPing图形化网络测试
- XMLHttpRequest Level2实现跨域
- TCP/IP协议概述
- Qt TCP通信,多线程服务器端
- 人工智能——神经网络算法初体验
- Android.Hook框架xposed篇(Http流量监控)