hello..
I am posting again, because I am tired of WA, that judge gives, though I am sure my solution is OK.
I think, that it is not because of eps value...
Maybe someone may have a fresh look at it.
(probably, the most important part is before the global "begin": functions for the solving!)
Code: Select all
program Project2;
{$APPTYPE CONSOLE}
{$R-}{$S-}{$Q-}
uses
SysUtils,
Math;
const
eps = 0.000001;
function d(const x1,y1,x2,y2: extended): extended;
begin
result := sqrt(sqr(x1-x2)+sqr(y1-y2))
end;
function s(const a,b,c: extended): extended;
var
p: extended;
begin
p := (a + b + c)/2.0;
result := sqrt (p*(p-a)*(p-b)*(p-c))
end;
function pointInCircle (const x,y,xc,yc,r: extended): boolean;
var
rd: extended;
begin
rd := d(x,y,xc,yc);
result := (rd - r < 0)
end;
function pointInRectangle (const x,y,x1,y1,x2,y2: extended): boolean;
begin
result := (x>x1) and (y<y1) and (x<x2) and (y>y2);
end;
function pointInTriangle (const x,y,x1,y1,x2,y2,x3,y3: extended): boolean;
var
a,b,c: extended;
a1,b1,c1: extended;
begin
a := d(x1,y1,x2,y2);
b := d(x1,y1,x3,y3);
c := d(x2,y2,x3,y3);
a1 := d(x,y,x2,y2);
b1 := d(x,y,x1,y1);
c1 := d(x,y,x3,y3);
result := abs(s(a,b,c) - s(a1,c1,c) - s(a1,b1,a) - s(b1,c1,b)) < eps
end;
type
figPoint = record
t: char;
ind: integer;
end;
circle = record
x,y,r: extended;
end;
rectangle = record
x1,y1,x2,y2: extended;
end;
triangle = record
x1,y1,x2,y2,x3,y3: extended;
end;
var
i,j,k,l,m,n,nc,nr,nt,ci: integer;
fig: array [1..100] of figPoint;
cir: array [1..100] of circle;
rec: array [1..100] of rectangle;
tri: array [1..100] of triangle;
x,y: extended;
c: char;
fl: boolean;
procedure out(const point,figure: integer);
begin
fl := true;
writeln ('Point ',point,' is contained in figure ',figure)
end;
begin
n := 0;
nr := 0;
nc := 0;
nt := 0;
while true do
begin
read (c);
if c = '*' then break;
inc(n);
fig[n].t := c;
case c of
'r':
begin
inc (nr);
fig[n].ind := nr;
readln (rec[nr].x1,rec[nr].y1,rec[nr].x2,rec[nr].y2)
end;
'c':
begin
inc (nc);
fig[n].ind := nc;
readln (cir[nc].x,cir[nc].y,cir[nc].r)
end;
't':
begin
inc(nt);
fig[n].ind := nt;
readln (tri[nt].x1,tri[nt].y1,tri[nt].x2,tri[nt].y2,tri[nt].x3,tri[nr].y3)
end;
end;
end;
ci := 0;
while true do
begin
readln (x,y);
if (x=9999.9) and (y=9999.9) then break;
inc(ci);
fl := false;
for i:=1 to n do
case fig[i].t of
'c':
if pointInCircle(x,y,cir[fig[i].ind].x,cir[fig[i].ind].y,cir[fig[i].ind].r) then
out (ci,i);
'r':
if pointInRectangle(x,y,rec[fig[i].ind].x1,rec[fig[i].ind].y1,rec[fig[i].ind].x2,rec[fig[i].ind].y2) then
out (ci,i);
't':
if pointInTriangle(x,y,tri[fig[i].ind].x1,tri[fig[i].ind].y1,tri[fig[i].ind].x2,tri[fig[i].ind].y2,tri[fig[i].ind].x3,tri[fig[i].ind].y3) then
out (ci,i);
end;
if not fl then
writeln ('Point ',ci,' is not contained in any figure');
end;
end.