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 1185. Wall

Help Needed...WA12 thanks a lot!
Posted by DR. Zhihua Lai 1 Apr 2013 19:44
What is wrong with this code


program Project4;
{$APPTYPE CONSOLE}

{$M 16777216}

uses
  Math;

type
  Pt = record
    x, y: integer;
  end;
  float = Extended;

function left(const p1, p2, p3: Pt): boolean; inline;
begin
  Result := ((p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x)) > 0;
end;

function dist(const p1, p2: Pt): float; inline;
begin
  Result := Sqrt(Sqr(p1.x - p2.x) + Sqr(p1.y - p2.y));
end;

var
  ans: float;
  i, n, l, j: integer;
  p, s: array[1..1001] of Pt;
  pointOnHull, endPoint: Pt;

begin
  Readln(n, l);
  pointOnHull.x := 1000001;
  pointOnHull.y := 1000001;
  for i := 1 to n do
  begin
    Readln(p[i].x, p[i].y);
    if (p[i].x < pointOnHull.x) then
    begin
      pointOnHull := p[i];
    end
    else
    if ((p[i].x = pointOnHull.x) and (p[i].y < pointOnHull.y)) then
    begin
      pointOnHull := p[i];
    end;
  end;
  j := 1;
  repeat
    s[j] := pointOnHull;
    endPoint := p[1];
    for i := 2 to n do
    begin
      if (((endpoint.x = pointOnHull.x) and (endpoint.y = pointOnHull.y)) or (left(p[i], pointOnHull, endpoint))) then
      begin
        endpoint := p[i];
      end;
    end;
    Inc(j);
    pointOnHull := endPoint;
  until (endPoint.x = s[1].x) and (endPoint.y = s[1].y);
  ans := dist(s[1], s[j - 1]);
  for i := 2 to j - 1 do
  begin
    ans := ans + dist(s[i], s[i - 1]);
  end;
  ans := Round(ans + 2 * PI * l);
  Writeln(ans:0:0);
  {$IFNDEF ONLINE_JUDGE}
  Readln;
  {$ENDIF}
end.


This uses 'gift-wrapping' algorithm described in http://en.wikipedia.org/wiki/Gift_wrapping_algorithm
but it can't pass test 12.
As you can see, I use 'extended', so it is not problem of precision.

Edited by author 01.04.2013 19:45

Edited by author 01.04.2013 19:47