[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


Sample Output

3

HINT

N<= 20
[Ahoi2009]fly <wbr>飞行棋

 

看完题目我震惊了。。省选竟然会出暴力瞬秒题。。。

一开始,我想到的是枚举两个点,是的它们的连线是圆的一条直径。然后递推两个顶点找到另外的直径,就能构成矩形。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);
  fori:=1 ton do
  begin
    readln(a[i]);
    a[n+1]:=a[i];c:=c+a[i];
  end;
  h:=cdiv 2;
  ifc*2<h then
  begin
    writeln('0');halt;
  end;
  s:=1;t:=0;
  whilenow+a[t+1]<=h do
  begin
    now:=a[t+1]+now;inc(t);
  end;
  ifs>t then
  begin
    writeln('0');
    halt;
  end;
  ifnow=h then inc(ans);
  ifnow=h then en:=t else en:=t+1
  whiles<en do
  begin
    now:=now-a[s];inc(s);
    whilenow+a[t+1]<=h do
    begin
      now:=a[t+1]+now;inc(t);
    end;
    ifnow=h then inc(ans);
    ift<s then
    begin
      writeln('0');
      halt;
    end;
  end;
  writeln((ans*(ans-1))shr 1);
end.
0 0
原创粉丝点击