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 1647. Divide an Island!

Why WA7 ?
Posted by Paul 18 Jun 2010 18:36
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  point=record
    x,y:extended;
  end;

function dist(a,b:point):extended;
  begin
    dist:=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  end;

procedure readp(var a:point);
  begin
    read(a.x,a.y);
  end;

procedure searchXY(a,b,c:extended; var x,y:extended);
  var
    p:extended;
  begin
    p:=(a+b+c)/2;
    if p*p-2*a*b<0 then
      begin
        x:=maxlongint;
        y:=maxlongint;
        exit;
      end;
    x:=(p+sqrt(p*p-2*a*b))/2;
    y:=(p-sqrt(p*p-2*a*b))/2;
  end;

var
  A,B,C:point;
  aa,bb,cc,x,y:extended;
  flagg:integer;

procedure print(a:point; x:extended; b:point; y:extended; c:point);
  var
    CA,CB:point;
  begin
    CA.x:=a.x-c.x;
    CA.y:=a.y-c.y;
    CB.x:=b.x-c.x;
    CB.y:=b.y-c.y;
    if (x/dist(a,c)*CA.x=y/dist(b,c)*CB.x)and(x/dist(a,c)*CA.y=y/dist(b,c)*CB.y) then
      begin
        flagg:=1;
        exit;
      end;
    writeln(x/dist(a,c)*CA.x+c.x:0:9,' ',x/dist(a,c)*CA.y+c.y:0:9);
    writeln(y/dist(b,c)*CB.x+c.x:0:9,' ',y/dist(b,c)*CB.y+c.y:0:9);
  end;

begin
  readp(A);
  readp(B);
  readp(C);
  aa:=dist(B,C);
  bb:=dist(A,C);
  cc:=dist(A,B);
  searchXY(aa,bb,cc,x,y);
  flagg:=0;
  if (x<aa)and(y<bb)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(b,x,a,y,c);
      if flagg=0 then
      halt;
    end;
  flagg:=0;
  if (x<bb)and(y<aa)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(a,x,b,y,c);
      if flagg=0 then
      halt;
    end;
  searchXY(aa,cc,bb,x,y);
  flagg:=0;
  if (x<aa)and(y<cc)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(c,x,a,y,b);
      if flagg=0 then
      halt;
    end;
  flagg:=0;
  if (x<cc)and(y<aa)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(a,x,c,y,b);
      if flagg=0 then
      halt;
    end;
  flagg:=0;
  searchXY(bb,cc,aa,x,y);
  if (x<bb)and(y<cc)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(c,x,b,y,a);
      if flagg=0 then
      halt;
    end;
  flagg:=0;
  if (x<cc)and(y<bb)and(x<>maxlongint) then
    begin
      writeln('YES');
      print(b,x,c,y,a);
      if flagg=0 then
      halt;
    end;
  writeln('NO');
end.

I know that it's "bugcode", but..