BZOJ1800: [Ahoi2009]fly 飞行棋

1800: [Ahoi2009]fly 飞行棋

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 773  Solved: 628
[Submit][Status]

Description

给出圆周上的若干个点,已知点与点之间的弧长,其值均为正整数,并依圆周顺序排列。 请找出这些点中有没有可以围成矩形的,并希望在最短时间内找出所有不重复矩形。

Input

第一行为正整数N,表示点的个数,接下来N行分别为这N个点所分割的各个圆弧长度

Output

所构成不重复矩形的个数

Sample Input

8
1
2
2
3
1
1
3
3


Sample Output

3

HINT

N<= 20

Source

题解:

大暴力术之术!

四个点构成矩形需要满足两个条件:

1.对边相等

2.对角线为直径

代码:

 1 var tot,i,j,k,l,n,ans,x:longint;
 2     a:array[0..25] of longint;
 3 procedure init;
 4  begin
 5    readln(n);
 6    a[0]:=0;
 7    for i:=1 to n do begin readln(x);a[i]:=a[i-1]+x;end;
 8  end;
 9 procedure main;
10  begin
11    tot:=a[n];
12    for i:=1 to n do
13     for j:=i+1 to n do
14      for k:=j+1 to n do
15       for l:=k+1 to n do
16        if (a[j]-a[i]=a[l]-a[k]) and (tot-(a[l]-a[j])=a[k]-a[i]) then inc(ans);
17    writeln(ans);
18  end;
19 
20 begin
21  assign(input,'input.txt');assign(output,'output.txt');
22  reset(input);rewrite(output);
23  init;
24  main;
25  close(input);close(output);
26 end.   
View Code
原文地址:https://www.cnblogs.com/zyfzyf/p/3910281.html