Time Limit: 10 Sec
Memory Limit: 64 MB
Description
给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。
Input
第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度
Output
所构成不重复矩形的个数
Sample Input
8
1
2
2
3
1
1
3
3
1
2
2
3
1
1
3
3
Sample Output
3
HINT
N<= 20
看完题目我震惊了。。省选竟然会出暴力瞬秒题。。。
一开始,我想到的是枚举两个点,是的它们的连线是圆的一条直径。然后递推两个顶点找到另外的直径,就能构成矩形。O(N*N)
然后,看到范围。。。我震惊了。。。直接暴力枚举四个点盼矩形。。。
最后,想到只要找到直径的总数m,然后直接算就可以了。。。m*(m-1)/2。
AC CODE
program
hy_1800;
var
a:
array
[
1..40
]
of
longint
;
n,i,now,c,h,s,t,en,ans:
longint
;
begin
readln(n);
for
i:=
1
to
n
do
begin
readln(a[i]);
a[n+
1
]:=a[i]; c:=c+a[i];
end
;
h:=c
div
2
;
if
c*
2
<h
then
begin
writeln
(
'0'
); halt;
end
;
s:=
1
; t:=
0
;
while
now+a[t+
1
]<=h
do
begin
now:=a[t+
1
]+now; inc(t);
end
;
if
s>t
then
begin
writeln
(
'0'
);
halt;
end
;
if
now=h
then
inc(ans);
if
now=h
then
en:=t
else
en:=t+
1
;
while
s<en
do
begin
now:=now-a[s]; inc(s);
while
now+a[t+
1
]<=h
do
begin
now:=a[t+
1
]+now; inc(t);
end
;
if
now=h
then
inc(ans);
if
t<s
then
begin
writeln
(
'0'
);
halt;
end
;
end
;
writeln
((ans*(ans-
1
))
shr
1
);
end
.