Why I got WA? Who can help me?
Posted by
Yang Yi 16 Oct 2002 16:26
var
c:array[0..100]of double;
a:array[0..100]of byte;
p:array[1..100,1..14]of double;
n,i,j:byte;
d,b,mx,my,p1,p2,p3,p4,p5,p6,p7,p8,r1,r2,c1,c2,c3,c4:double;
begin
read(n);
for i:=1to n do
begin
read(p1,p2,p3,p4);a[i]:=i;
d:=sqrt(sqr(p1-p3)+sqr(p2-p4));
mx:=(p1+p3)/2;my:=(p2+p4)/2;
p5:=mx+p2-my;p6:=my+mx-p1;
p7:=mx-p2+my;p8:=my-mx+p1;
if p1=p5 then r1:=1e2466else r1:=(p2-p6)/(p1-p5);if r1=0then
r2:=1e2466else r2:=-1/r1;
c1:=p1*r1-p2;c2:=p7*r1-p8;c3:=p5*r2-p6;c4:=p7*r2-p8;
p[i,1]:=p1;p[i,2]:=p2;p[i,3]:=p3;p[i,4]:=p4;p[i,5]:=p5;p
[i,6]:=p6;p[i,7]:=p7;p[i,8]:=p8;
p[i,9]:=r1;p[i,10]:=r2;p[i,11]:=c1;p[i,12]:=c2;p[i,13]:=c3;p
[i,14]:=c4
end;
read(p1,p2);
for i:=1to n do
if abs(p[i,1]-p[i,3])=abs(p[i,2]-p[i,4])then
begin
if((p1>=p[i,1])and(p1<=p[i,3])or(p1<=p[i,1])and(p1>=p[i,3]))and
((p2>=p[i,2])and(p2<=p[i,4])or(p2<=p[i,2])and(p2>=p[i,4]))then c
[i]:=0
else if(p1>=p[i,1])and(p1<=p[i,3])or(p1<=p[i,1])and(p1>=p[i,3])
then
if abs(p2-p[i,2])<abs(p2-p[i,4])then c[i]:=abs(p2-p[i,2])else c
[i]:=abs(p2-p[i,4])
else if(p2>=p[i,2])and(p2<=p[i,4])or(p2<=p[i,2])and(p2>=p[i,4])
then
if abs(p1-p[i,1])<abs(p1-p[i,3])then c[i]:=abs(p1-p[i,1])else c
[i]:=abs(p1-p[i,3])
else begin
c1:=sqrt(sqr(p1-p[i,1])+sqr(p2-p[i,2]));
c2:=sqrt(sqr(p1-p[i,3])+sqr(p2-p[i,4]));
c3:=sqrt(sqr(p1-p[i,5])+sqr(p2-p[i,6]));
c4:=sqrt(sqr(p1-p[i,7])+sqr(p2-p[i,8]));
if(c1<=c2)and(c1<=c3)and(c1<=c4)then c[i]:=c1 else
if(c2<=c1)and(c2<=c3)and(c2<=c4)then c[i]:=c2 else
if(c3<=c1)and(c3<=c2)and(c3<=c4)then c[i]:=c3 else
if(c4<=c1)and(c4<=c2)and(c4<=c3)then c[i]:=c4
end
end else
begin
if((p[i,9]*p1-p2>p[i,11])and(p[i,9]*p1-p2>p[i,12])or(p[i,9]*p1-
p2<p[i,11])and(p[i,9]*p1-p2<p[i,12]))and
((p[i,10]*p1-p2>p[i,13])and(p[i,10]*p1-p2>p[i,14])or(p[i,10]*p1-
p2<p[i,13])and(p[i,10]*p1-p2<p[i,14]))then
begin
c1:=sqrt(sqr(p1-p[i,1])+sqr(p2-p[i,2]));
c2:=sqrt(sqr(p1-p[i,3])+sqr(p2-p[i,4]));
c3:=sqrt(sqr(p1-p[i,5])+sqr(p2-p[i,6]));
c4:=sqrt(sqr(p1-p[i,7])+sqr(p2-p[i,8]));
if(c1<=c2)and(c1<=c3)and(c1<=c4)then c[i]:=c1 else
if(c2<=c1)and(c2<=c3)and(c2<=c4)then c[i]:=c2 else
if(c3<=c1)and(c3<=c2)and(c3<=c4)then c[i]:=c3 else
if(c4<=c1)and(c4<=c2)and(c4<=c3)then c[i]:=c4
end else if((p[i,9]*p1-p2>=p[i,11])and(p[i,9]*p1-p2<=p[i,12])or(p
[i,9]*p1-p2<=p[i,11])and(p[i,9]*p1-p2>=p[i,12]))and
((p[i,10]*p1-p2<=p[i,13])and(p[i,10]*p1-p2>=p[i,14])or(p[i,10]*p1-
p2>=p[i,13])and(p[i,10]*p1-p2<=p[i,14]))then c[i]:=0 else
if(p[i,9]*p1-p2>p[i,11])and(p[i,9]*p1-p2<p[i,12])or(p[i,9]*p1-p2<p
[i,11])and(p[i,9]*p1-p2>p[i,12])then
begin
c1:=abs(p[i,10]*p1-p2-p[i,14])/sqrt(sqr(p[i,10])+1);
c2:=abs(p[i,10]*p1-p2-p[i,13])/sqrt(sqr(p[i,10])+1);
if c1<c2 then c[i]:=c1 else c[i]:=c2
end else
begin
c1:=abs(p[i,9]*p1-p2-p[i,12])/sqrt(sqr(p[i,9])+1);
c2:=abs(p[i,9]*p1-p2-p[i,11])/sqrt(sqr(p[i,9])+1);
if c1<c2 then c[i]:=c1 else c[i]:=c2
end
end;
for i:=1to n-1do
for j:=i+1to n do
if(c[i]>c[j])or(c[i]=c[j])and(a[i]>a[j])then
begin
c[0]:=c[i];c[i]:=c[j];c[j]:=c[0];
a[0]:=a[i];a[i]:=a[j];a[j]:=a[0]
end;
for i:=1to n do
write(a[i],' ')
end.