【codevs 1006】等差数列
来源:互联网 发布:人类起源于中国知乎 编辑:程序博客网 时间:2024/05/24 06:55
1006 等差数列
时间限制: 1 s
空间限制: 128000 KB
题目等级 : 黄金 Gold
题解
题目描述 Description
给定n(1<=n<=100)个数,从中找出尽可能多的数使得他们能够组成一个等差数列.求最长的等差数列的长度.
输入描述 Input Description
第一行是一个整数n,接下来一行包括了n个数,每个数的绝对值不超过10000000.
输出描述 Output Description
对于每个输入数据,输出你所找出的最长等差数列的长度
样例输入 Sample Input
7
3
8
4
5
6
2
2
样例输出 Sample Output
5
数据范围及提示 Data Size & Hint
枚举公差即可~
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#include <vector>using namespace std;int n,x,d;//公差;vector < int > s;int ans;int main(){ scanf("%d",&n); for(int i = 1;i <= n;i ++) { scanf("%d",&x); s.push_back(x); } sort(s.begin(),s.end()); for(int i = 0;i < n;i ++) { int sum = 1; for(int j = i + 1; j < n;j ++) { if(j == i + 1) d = s[j] - s[i]; if(s[j] - s[i] == d * sum) sum ++; }//以每一个数作为开头,枚举公差 ans = max(ans,sum); } printf("%d\n",ans); return 0;}
0 0
- Codevs 1006 等差数列
- 【codevs 1006】等差数列
- codevs 1006 等差数列 题解报告
- codevs 1006 等差数列 解题报告
- codevs等差数列
- codevs p1006 等差数列
- 1006等差数列
- 1006 等差数列
- wikioi 1006 等差数列
- Code[vs]1006 等差数列
- CODE[VS] 1006 等差数列
- CODE[VS] 1006 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- concat连接多个通道
- Redis实战之Redis + Jedis
- bower ENOINT Register requires an interactive shell
- 面试中最易被“秒杀”的五种表现
- Redis实战
- 【codevs 1006】等差数列
- 模仿知乎首页代码
- 通过 AWS 的 Lambda 和 API Gateway 走向 Serverless
- Shell脚本编程初体验
- 如何用MathType编辑直角三角形符号
- 【Java每日一题】20161111
- Redis实战之征服 Redis + Jedis + Spring (一)
- 看《程序员的呐喊》有感
- jos学习中的分段分页机制