/*
PROG: theme
LANG: C++
*/
#include
<
iostream
>
using
namespace
std;
int
N;
int
ans
=
0
;
int
a[
5001
];
void
init()
{
scanf(
"
%d
"
,
&
N);
for
(
int
i
=
1
;i
<=
N;
++
i)
scanf(
"
%d
"
,
&
a[i]);
}
void
solve()
{
for
(
int
i
=
N
-
5
;i
>=
5
;
--
i){
//
枚举位置差
int
len
=
1
,cha
=
100
;
for
(
int
j
=
1
;j
<=
N
-
i;
++
j)
//
枚举一端开头,则另一端也就知道了
if
(a[j]
-
a[j
+
i]
==
cha){
//
做差比较
if
(len
<
i) len
++
;
if
(ans
<
len) ans
=
len;
if
(i
==
len)
break
;
//
当达到枚举长度时则跳出
}
else
{
len
=
1
;
cha
=
a[j]
-
a[j
+
i];
//
差值
}
if
(ans
>=
i)
break
;
//
当长度大于或等于时可以直接跳出了,下面枚举的长度不会大于ans的
}
if
(ans
>=
5
) printf(
"
%d\n
"
,ans);
else
printf(
"
0\n
"
);
}
int
main()
{
freopen(
"
theme.in
"
,
"
r
"
,stdin);
freopen(
"
theme.out
"
,
"
w
"
,stdout);
init();
solve();
return
0
;
}
/*
Executing
Test 1: TEST OK [0.000 secs, 2816 KB]
Test 2: TEST OK [0.011 secs, 2816 KB]
Test 3: TEST OK [0.011 secs, 2816 KB]
Test 4: TEST OK [0.000 secs, 2816 KB]
Test 5: TEST OK [0.011 secs, 2816 KB]
Test 6: TEST OK [0.000 secs, 2816 KB]
Test 7: TEST OK [0.000 secs, 2816 KB]
Test 8: TEST OK [0.000 secs, 2816 KB]
Test 9: TEST OK [0.011 secs, 2816 KB]
Test 10: TEST OK [0.000 secs, 2816 KB]
Test 11: TEST OK [0.065 secs, 2816 KB]
Test 12: TEST OK [0.065 secs, 2816 KB]
Test 13: TEST OK [0.032 secs, 2816 KB]
Test 14: TEST OK [0.054 secs, 2816 KB]
Test 15: TEST OK [0.011 secs, 2816 KB]
*/
posted on 2009-07-15 10:58
xfstart07 阅读(89)
评论(0) 编辑 收藏 引用