比赛 |
20120419x |
评测结果 |
AETTEEETEE |
题目名称 |
最长数列 |
最终得分 |
10 |
用户昵称 |
Citron酱 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-04-19 15:56:13 |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#define I_F "series.in"
#define O_F "series.out"
const short MAXn=100;
const short P=20;
short n;
int s[MAXn];
inline short Max(const short&, const short&);
inline short Max(const short&, const short&, const short&, const short&);
template<typename Any>
inline void Swap(Any&, Any&);
void Sort(int*, const short&, const short&);
short Log(const int&, const int&);
short h0();
short h1();
short h2();
short h3();
int main()
{
int m;
freopen(I_F,"r",stdin);
freopen(O_F,"w",stdout);
for (scanf("%d",&m); m>0; m--)
{
scanf("%hd",&n);
for (short i=0; i<n; scanf("%d",&s[i++]));
Sort(s,0,n-1);
printf("%hd\n",Max(h0(),h1(),h2(),h3()));
}
return 0;
}
inline short Max(const short &a, const short &b)
{
return (a>b)?a:b;
}
inline short Max(const short &a, const short &b, const short &c, const short &d)
{
return Max(Max(a,b),Max(c,d));
}
template<typename Any>
inline void Swap(Any &a, Any &b)
{
Any t=a;
a=b;
b=t;
}
void Sort(int *s, const short &l, const short &r)
{
if (r-l>P)
{
int x=s[l+rand()%(r-l+1)];
short i=l, j=r;
do
{
while (s[i]<x) ++i;
while (s[j]>x) --j;
if (i<=j)
Swap(s[i++],s[j--]);
} while (i<j);
if (i<r) Sort(s,i,r);
if (l<j) Sort(s,l,j);
}
else
{
bool flag=true;
for (short i=l; i<r && flag; ++i)
{
flag=false;
for (short j=r; j>i; --j)
if (s[j-1]>s[j])
Swap(s[j-1],s[j]),
flag=true;
}
}
}
short Log(const int &a, const int &b)
{
if (a==b)
return -2;
int t;
short i=2;
for (t=a*a; t<b; ++i)
t*=a;
return (t==b)?i:-2;
}
short h0()
{
short ans=1, t=1;
for (short i=1; i<n; i++)
if (s[i]!=s[i-1])
{
ans=Max(ans,t);
t=1;
}
else
++t;
return Max(ans,t);
}
short h1()
{
int m[MAXn*MAXn], k=-1;
for (short i=0; i<n; ++i)
for (short j=i+1; j<n; ++j)
if (s[i]!=s[j])
m[++k]=s[j]-s[i];
if (k>0)
Sort(m,0,k);
short ans=1, t=1;
for (int i=1; i<=k; i++)
if (m[i]!=m[i-1])
{
ans=Max(ans,t);
t=1;
}
else
++t;
return Max(ans,t)+1;
}
short h2()
{
int m[MAXn*MAXn], k=-1;
for (short i=0; i<n; ++i)
for (short j=0; j<n; ++j)
if (s[i]!=s[j] && s[j]%s[i]==0)
m[++k]=s[j]/s[i];
if (k>0)
Sort(m,0,k);
short ans=1, t=1;
for (int i=1; i<=k; i++)
if (m[i]!=m[i-1])
{
ans=Max(ans,t);
t=1;
}
else
++t;
return Max(ans,t)+1;
}
short h3()
{
int m[MAXn*MAXn], k=-1, tt;
for (short i=0; i<n; ++i)
if (s[i]>1)
for (short j=i+1; j<n; ++j)
{
tt=Log(s[i],s[j]);
if (tt>-2)
m[++k]=tt;
}
if (k>0)
Sort(m,0,k);
short ans=1, t=1;
for (int i=1; i<=k; i++)
if (m[i]!=m[i-1])
{
ans=Max(ans,t);
t=1;
}
else
++t;
return Max(ans,t)+1;
}