1800: [ahoi2009] Fly time limit: 10 sec memory limit: 64 MB
Submit: 773 solved: 628
[Submit] [Status] Description is a number of points on the circumference. The Arc lengths between known points and points are all positive integers and arranged in a circular order. Find out if the dots can enclose the Rectangles and find all non-repeating rectangles in the shortest time. Input the first positive integer N, indicating the number of points. The next n rows represent the number of non-repeated rectangles formed by the arc lengths separated by the N points. Sample input8
1
2
2
3
1
1
3
3
Sample output3
Hint
N <= 20
Source
Question:
Great brute force!
The following conditions must be met when four vertices form a rectangle:
1. Equal sides
2. the diagonal line is the diameter.
Code:
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 begin11 tot:=a[n];12 for i:=1 to n do13 for j:=i+1 to n do14 for k:=j+1 to n do15 for l:=k+1 to n do16 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 begin21 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