codevs——T1006 等差数列
给定n(1<=n<=100)个数,从中找出尽可能多的数使得他们能够组成一个等差数列.求最长的等差数列的长度.
第一行是一个整数n,接下来一行包括了n个数,每个数的绝对值不超过10000000.
对于每个输入数据,输出你所找出的最长等差数列的长度
7
3
8
4
5
6
2
2
5
爆搜
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- int n,num[],ans,cnt;
- void DFS(int pos,int poor)
- {
- if(pos==n+) return ;
- for(int i=pos+;i<=n;i++)
- {
- if(num[i]-num[pos]==poor)
- cnt++,DFS(i,poor);
- }
- }
- int main()
- {
- scanf("%d",&n);
- for(int i=;i<=n;i++)
- scanf("%d",num+i);
- if(n==)
- {
- puts("");
- return ;
- }
- sort(num+,num+n+);
- for(int i=;i<n;i++)
- for(int j=i+;j<=n;j++)
- {
- cnt=;
- DFS(i,num[j]-num[i]);
- ans=max(ans,cnt);
- }
- printf("%d",ans);
- return ;
- }
codevs——T1006 等差数列的更多相关文章
- codevs 1006 等差数列
提交地址:http://codevs.cn/problem/1006/ 1006 等差数列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Des ...
- codevs——1006 等差数列
1006 等差数列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给定n(1<=n< ...
- codevs 等差数列
1006 等差数列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 给定n(1<=n<=100) ...
- 洛谷P2424/codevs 2606 约数和
http://codevs.cn/problem/2606/ https://luogu.lohu.info/problem/show?pid=2424 题目背景 Smart最近沉迷于对约数的研究中. ...
- code1006 等差数列
我绞尽脑汁想一个更好的算法,然而不能如愿,只好写一个n^3的了 很简单,就是暴力搜索(还好n<100) 先排序,然后循环i=1ton,j=i+1ton 把a[i]a[j]确定为等差数列开始的两个 ...
- 【BZOJ 2124】【CodeVS 1283】等差子序列
http://www.lydsy.com/JudgeOnline/problem.php?id=2124 http://codevs.cn/problem/1283/ 重点是把判断是否存在3个数组成等 ...
- codevs 3289 花匠
题目:codevs 3289 花匠 链接:http://codevs.cn/problem/3289/ 这道题有点像最长上升序列,但这里不是上升,是最长"波浪"子序列.用动态规划可 ...
- codevs 1082 线段树练习 3(区间维护)
codevs 1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...
- codevs 1285 二叉查找树STL基本用法
C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...
随机推荐
- 英语音乐---二、Burning
英语音乐---二.Burning 一.总结 一句话总结:Burning - Maria Arredondo 玛丽亚·亚瑞唐多(Maria Arredondo),1985年7月6日出生于文内斯拉小镇,挪 ...
- layer是什么
layer是什么 总结 layer就是一个web弹框 简介 layer是一款web弹层组件,致力于服务各个水平段的开发人员. 可以让你想到即可做到的web弹窗 概述 [1] layer,一个可以让你 ...
- 5.不用拷贝的对象可以用ref
#include <iostream> #include <string> #include <boost/bind.hpp> #include <boost ...
- POJ 3145 线段树 分块?+暴力
思路: 线段树 (分类讨论) 此题数据很水 数据很水 数据很水 但是卡个暴力还是没问题的-- //By SiriusRen #include <cstdio> #include <c ...
- springMVC接受前台传值
今天,用ajax向springMVC的控制器传参数,是一个json对象.({"test":"test","test1":"test ...
- js相关禁止
遇到网页上有精美图片或者精彩文字想保存时,通常大家都是选中目标后按鼠标右键,在弹出菜单中选择“图片另存为”或“复制”来达到我们的目的.但是,目前有许多网页都屏蔽了鼠标右键,那么用js如何实现禁止鼠标右 ...
- vue.js技巧小计
//删除数组索引方法01 del (index) { this.arr.splice(index ,1); } //删除数组索引方法01 del (index) { this.$delete(this ...
- Mojo C++ Platform API
Mojo C++ Platform API This document is a subset of the Mojo documentation. Contents Overview Platfor ...
- [Jsoi2010]连通数 bitset + Floyd
Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...
- mysql的关联查询简写
平常的内连接查询: SELECT * from ab_style as a INNER JOIN ab_url as b on a.style_bold=b.url_id 可支持简写风格: selec ...