ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1130. Nikifor's Walk

Please!!! what is wrong with my code. WA2?????????????
Posted by Shohruh 6 Jan 2013 23:48
program acm_1130;

type vec=record
x,y:longint;
end;

var w,a:array[1..3]of vec;
    c,b:vec;
    i,n,nn:longint;
    L:longint;
    p:array[0..10000,1..3,1..2] of byte;
    q:array[0..10000,1..3]of shortint;
    f:boolean;

procedure delta(nn,r:longint);
var j:longint;
begin
 if nn=0 then exit;
 for j:=1 to 2 do
 if p[nn,r,j]>0 then
 begin
  q[nn-1,p[nn,r,j]]:=-q[nn-1,p[nn,r,j]];
  delta(nn-1,p[nn,r,j]);
 end;
end;

procedure minn(i:longint);
begin
  if sqr(a[1].x+a[2].x)+sqr(a[1].y+a[2].y)<=sqr(L) then
  begin
   w[1].x:=a[1].x+a[2].x;
   w[1].y:=a[1].y+a[2].y;
   w[2]:=a[3];
   q[i,1]:=1; q[i,2]:=1; q[i,3]:=1;
   p[i+1,1,1]:=1; p[i+1,1,2]:=2; p[i+1,2,1]:=3;
   exit;
  end;
  if sqr(a[1].x-a[2].x)+sqr(a[1].y-a[2].y)<=sqr(L) then
  begin
   w[1].x:=a[1].x+a[2].x;
   w[1].y:=a[1].y+a[2].y;
   w[2]:=a[3];
   q[i,1]:=1; q[i,2]:=-1; q[i,3]:=1;
   p[i+1,1,1]:=1; p[i+1,1,2]:=2; p[i+1,2,1]:=3; exit;
  end;
  if sqr(a[1].x+a[3].x)+sqr(a[1].y+a[3].y)<=sqr(L) then
  begin
   w[1].x:=a[1].x+a[3].x;
   w[1].y:=a[1].y+a[3].y;
   w[2]:=a[2];
   q[i,1]:=1; q[i,2]:=1; q[i,3]:=1;
   p[i+1,1,1]:=1; p[i+1,1,2]:=3; p[i+1,2,1]:=2; exit;
  end;
  if sqr(a[1].x-a[3].x)+sqr(a[1].y-a[3].y)<=sqr(L) then
  begin
   w[1].x:=a[1].x-a[3].x;
   w[1].y:=a[1].y-a[3].y;
   w[2]:=a[2];
   q[i,1]:=1; q[i,2]:=1; q[i,3]:=-1;
   p[i+1,1,1]:=1; p[i+1,1,2]:=3; p[i+1,2,1]:=2; exit;
  end;
  if sqr(a[2].x+a[3].x)+sqr(a[2].y+a[3].y)<=sqr(L) then
  begin
   w[1].x:=a[2].x+a[3].x;
   w[1].y:=a[2].y+a[3].y;
   w[2]:=a[2];
   q[i,1]:=1; q[i,2]:=1; q[i,3]:=1;
   p[i+1,1,1]:=2; p[i+1,1,2]:=3; p[i+1,2,1]:=1;
   exit;
  end;
  if sqr(a[2].x-a[3].x)+sqr(a[2].y-a[3].y)<=sqr(L) then
  begin
   w[1].x:=a[2].x-a[3].x;
   w[1].y:=a[2].y-a[3].y;
   w[2]:=a[2];
   q[i,1]:=1; q[i,2]:=1; q[i,3]:=-1;
   p[i+1,1,1]:=2; p[i+1,1,2]:=3; p[i+1,2,1]:=1;
   exit;
  end;
end;

begin
  read(n);
  read(L);
  if n=1 then begin write('+'); exit; end;
  if n=2 then
  begin
   read(c.x,c.y);
   read(b.x,b.y);
   if sqr(c.x-b.x)+sqr(c.y-b.y)<sqr(c.x+b.x)+sqr(c.y+b.y) then
   writeln('+-') else writeln('++');
   exit;
  end;
  for i:=1 to 3 do read(a[i].x,a[i].y);
  fillchar(p,sizeof(p),0);
  fillchar(q,sizeof(q),1);

  minn(0); a[1]:=w[1]; a[2]:=w[2];

  for i:=1 to n-3 do
  begin
   read(a[3].x,a[3].y);
   minn(i); a[1]:=w[1]; a[2]:=w[2];
  end;

  f:=true;
  if sqr(a[1].x-a[2].x)+sqr(a[1].y-a[2].y)<sqr(a[1].x+a[2].x)+sqr(a[1].y+a[2].y) then
  f:=true else f:=false;

  if f then
  begin
   nn:=n-2;
   delta(nn,2);
  end;
  writeln('YES');
  for i:=1 to 3 do
  if q[0,i]>0 then write('+') else write('-');
  for i:=1 to n-3 do
  if q[i,3]>0 then write('+') else write('-');

end.

Edited by author 07.01.2013 14:31