Bzoj1800: [ahoi2009] Fly chess

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.