|
|
back to boardI had puzzle,why I got WA?Can you help me~ {}{$N+} {} {}program P1111; {} {}{Squares} {} {}type Zieve=array[1..4] of record {----------------------------}x,y:double; {--------------------------}end; {} {}var n:integer; {----}x0,y0:double; {----}list:array[1..100] of integer; {----}l:array[1..100] of double; {----}cr:array[1..100] of Zieve; {} {-}procedure change(var a,b:double); {} {-}var c:double; {} {-}begin {} {---}c:=a; {---}a:=b; {---}b:=c; {} {-}end; {} {-}procedure init; {} {-}var i:integer; {-----}x1,x2,y1,y2:double; {} {-}begin {} {---}read(n); {---}for i:=1 to n do {---}begin {-----}read(x1,y1,x2,y2); {-----}if x1>x2 then change(x1,x2); {-----}if y1>y2 then change(y1,y2); {-----}cr[i,1].x:=x1; {-----}cr[i,1].y:=y1; {-----}cr[i,2].x:=x1; {-----}cr[i,2].y:=y2; {-----}cr[i,3].x:=x2; {-----}cr[i,3].y:=y1; {-----}cr[i,4].x:=x2; {-----}cr[i,4].y:=y2; {---}end; {---}read(x0,y0); {} {-}end; {} {-}function long(z:Zieve):double; {} {-}var r,min:double; {-----}i:integer; {} {-}begin {} {---}if (x0>=z[1].x)and(x0<=z[4].x)and {------}(y0>=z[1].y)and(y0<=z[4].y) then min:=0 else {---}begin {-----}min:=1e+30; {-----}if (x0>=z[1].x)and(x0<=z[4].x) then {-----}begin {-------}r:=sqr(z[1].y-y0); {-------}if r<min then min:=r; {-------}r:=sqr(z[4].y-y0); {-------}if r<min then min:=r; {-----}end {-----}else {-----}if (y0>=z[1].y)and(y0<=z[4].y) then {-----}begin {-------}r:=sqr(z[1].x-x0); {-------}if r<min then min:=r; {-------}r:=sqr(z[4].x-x0); {-------}if r<min then min:=r; {-----}end {-----}else {-----}begin {-------}for i:=1 to 4 do {-------}begin {---------}r:=sqr(z[i].x-x0)+sqr(z[i].y-y0); {---------}if r<min then min:=r; {-------}end; {-----}end; {---}end; {} {---}long:=min; {} {-}end; {} {-}procedure main; {} {-}var i,j,k:integer; {} {-}begin {} {---}for i:=1 to n do {---}begin {-----}list[i]:=i; {-----}l[i]:=long(cr[i]); {---}end; {} {---}for i:=1 to n-1 do {---}begin {-----}k:=i; {-----}for j:=i+1 to n do {-------}if (l[list[k]]>l[list[j]])or((abs(l[list[k]]-l[list[j]])<1e-14)and(list[k]>list[j])) then k:=j; {-----}j:=list[k]; {-----}list[k]:=list[i]; {-----}list[i]:=j; {---}end; {} {---}for i:=1 to n do write(list[i],' '); {} {-}end; {} {}begin {} {--}init; {--}main; {} {}end. Edited by author 28.06.2004 14:01 Funny problem (+) The sides of square can be not parallel to the axes, i.e. square 0 0 1 0 is possible :) Re: Funny problem (+) Thanks~~ |
|
|