bzoj 1800 暴力枚举

直接暴力枚举四个点,然后判断是否能组成矩形就行了

注意枚举的点的标号从小到大,保证不重复枚举

/**************************************************************
    Problem: 1800
    User: BLADEVIL
    Language: Pascal
    Result: Accepted
    Time:0 ms
    Memory:224 kb
****************************************************************/
 
//By BLADEVIL
var
    n                           :longint;
    sum                         :array[0..21] of longint;
    i, j, k, l                  :longint;
    a, b, c, d                  :longint;
    tot, ans                    :longint;
     
function min(a,b:longint):longint;
begin
    if a>b then min:=b else min:=a;
end;
     
begin
    read(n);
    for i:=2 to n+1 do read(sum[i]);
    for i:=2 to n+1 do inc(tot,sum[i]);
    for i:=1 to n do sum[i]:=sum[i]+sum[i-1];
    for i:=1 to n do
        for j:=i+1 to n do
            for k:=j+1 to n do
                for l:=k+1 to n do
                begin
                    a:=sum[j]-sum[i];
                    a:=min(tot-a,a);
                    b:=sum[k]-sum[j];
                    b:=min(tot-b,b);
                    c:=sum[l]-sum[k];
                    c:=min(c,tot-c);
                    d:=abs(sum[l]-sum[i]);
                    d:=min(d,tot-d);
                    if (a=c) and (b=d) then inc(ans);
                end;
    writeln(ans);
end.
原文地址:https://www.cnblogs.com/BLADEVIL/p/3500879.html