VECTOR – spoj

Đề bài:

Thuật toán:

Code:

const
  fi='';
  fo='';
  maxn=30;
  oo=5000;
var
  d : array[-oo..oo,-oo..oo] of longint;
  x,y : array[1..maxn] of longint ;
  i,j,n,u,v,xx,yy,s1,s2 : longint;
  res : int64;
procedure enter;
  begin
    assign(input,fi);reset(input);
    read(n);
    for i:=1 to n do read(x[i],y[i]);
    read(u,v);
    close(input);
  end;
procedure up1;
  begin
    inc(d[xx,yy]);
  end;
procedure try1(i : longint);
  var j: longint;
  begin
    for j:=0 to 1 do
      begin
        if j=1 then begin xx:=xx+x[i]; yy:=yy+y[i]; end;
        if i=s1 then up1 else try1(i+1);
        if j=1 then begin xx:=xx-x[i]; yy:=yy-y[i] end;
      end;
  end;
procedure up2;
  var tg1,tg2 : longint;
  begin
    tg1 := u - xx;
    tg2 := v - yy;
    if (tg1<=oo) and(tg1>=-oo) then
    if (tg2<=oo) and (tg2>=-oo) then inc(res,d[tg1,tg2]);
  end;
procedure try2(i : longint);
  var j: longint;
  begin
    for j:=0 to 1 do
      begin
        if j=1 then begin xx:=xx+x[i]; yy:=yy+y[i]; end;
        if i=n then up2 else try2(i+1);
        if j=1 then begin xx:=xx-x[i]; yy:=yy-y[i] end;
      end;
  end;
procedure process;
  begin
    s1 := n div 2; s2 := s1+1;
    xx := 0; yy:=0;
    try1(1);
    xx := 0; yy:=0;
    try2(s2);
  end;
procedure print;
  begin
    assign(output,fo);rewrite(output);
    writeln(res);
    close(output);
  end;
begin
  enter;
  process;
  print;
end.
Khuyên dùng

 

About Aida Nana

Nghề chính là chém gió, quăng bom và ném lựu đạn.
Nghề phụ là cắt cỏ, chém chuối, cưa cây......

Trackbacks

Speak Your Mind

*