[Ahoi2009]fly 飞行棋
来源:互联网 发布:期货农产品数据库建立 编辑:程序博客网 时间:2024/06/09 03:52
Time Limit: 10Sec MemoryLimit: 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。
ACCODE
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
.
0 0
- [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 【BZOJ1800】【Ahoi2009】fly 飞行棋
- [BZOJ1800][Ahoi2009]fly飞行棋
- 【AHOI2009】【BZOJ1800】fly 飞行棋
- [BZOJ1800] [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- BZOJ1800: [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- bzoj1800: [Ahoi2009]fly 飞行棋
- bzoj1800 [Ahoi2009]fly 飞行棋
- 1800: [Ahoi2009]fly 飞行棋
- 【bzoj1800】[Ahoi2009]fly 飞行棋
- bzoj 1800 [Ahoi2009] fly 飞行棋
- bzoj1800: [Ahoi2009]fly 飞行棋 统计直径
- BZOJ 1800 AHOI2009 fly 飞行棋 暴力
- BZOJ 1800 [Ahoi2009]fly 飞行棋
- 扩展欧几里得
- poj 1061 青蛙的约会
- Splay Tree
- poj 3468 A Simple Problem with I…
- [JSOI2008]火星人prefix
- [Ahoi2009]fly 飞行棋
- poj 2387 Til the Cows Come Home
- poj 3128 Leonardo's Notebook
- 多米诺覆盖
- Charm Bracelet
- poj 3093 Margaritas on the River…
- poj 1276 Cash Machine
- poj 1742 Coins
- poj 1014 Dividing