program dreiecke;
var n:integer;
x1i,y1i,x2i,y2i,x3i,y3i:integer;
x1,y1,x2,y2,x3,y3:real;
d1,d2,d3,d1s,d2s,d3s:real;
c1,c2,c3,c0,cc,pd:longint;
function distance(x1d,y1d,x2d,y2d:real):real;
var xd,yd:real;
begin
xd:=x2d-x1d;
yd:=y2d-y1d;
distance:=sqrt(xd*xd+yd*yd);
end;
function senkend(x1s,y1s,x2s,y2s,x3s,y3s:real):real;
var ax0,by0,c,d:real;
begin
ax0:=+(y2s-y1s)*x3s;
by0:=-(x2s-x1s)*y3s;
c:=(x2s-x1s)*y1s-(y2s-y1s)*x1s;
d:=distance(x1s,y1s,x2s,y2s);
if d=0 then senkend:=0 else senkend:=(ax0+by0+c)/d;
senkend:=abs(senkend);
end;
begin
readln(n);
for x1i:=1 to n do
for y1i:=1 to n do
for x2i:=1 to n do
for y2i:=1 to n do
for x3i:=1 to n do
for y3i:=1 to n do
begin
x1:=x1i/n;
y1:=y1i/n;
x2:=x2i/n;
y2:=y2i/n;
x3:=x3i/n;
y3:=y3i/n;
d1:=distance(x2,y2,x3,y3);
d2:=distance(x1,y1,x3,y3);
d3:=distance(x1,y1,x2,y2);
d1s:=senkend(x2,y2,x3,y3,x1,y1);
d2s:=senkend(x1,y1,x3,y3,x2,y2);
d3s:=senkend(x1,y1,x2,y2,x3,y3);
pd:=1;
if d1s>d2 then pd:=3;
if d1s>d3 then pd:=3;
if d2s>d1 then pd:=3;
if d2s>d3 then pd:=3;
if d3s>d1 then pd:=3;
if d3s>d2 then pd:=3;
if d1s=d2 then pd:=2;
if d1s=d3 then pd:=2;
if d2s=d1 then pd:=2;
if d2s=d3 then pd:=2;
if d3s=d1 then pd:=2;
if d3s=d2 then pd:=2;
if d1s=0 then pd:=0;
if d2s=0 then pd:=0;
if d3s=0 then pd:=0;
if pd=0 then c0:=c0+1;
if pd=1 then c1:=c1+1;
if pd=2 then c2:=c2+1;
if pd=3 then c3:=c3+1;
end;
cc:=c0+c1+c2+c3;
writeln(100*c0/cc);
writeln(100*c1/cc);
writeln(100*c2/cc);
writeln(100*c3/cc);
writeln(100*(c0+c1)/cc);
writeln(100*(c2+c3)/cc);
writeln('finished');
readln;
end.
其中:
distance是测得两点间距离的函数。
senkend是测得一点到另外两点连成直线的距离的函数。