|
|
вернуться в форумWhat's wrong with my program?Please help me! Послано xzl 21 фев 2002 06:21 const limit =1000; type Tnode =record id :integer; dig :extended; end; var s :array[1..limit] of Tnode; n :integer; procedure init; var x,y,bx,by :extended; i :integer; begin read(bx,by,n); for i:=1 to n do with s[i] do begin read(x,y,id); x:=x-bx;y:=y-by;dig:=abs(y)/sqrt(x*x+y*y); if y>0 then if x>0 then dig:=1-dig else dig:=3+dig else if x>0 then dig:=1+dig else dig:=3-dig end; end; procedure sift(p,tot:integer); var i,q :integer; d :extended; begin i:=s[p].id;d:=s[p].dig; while true do begin q:=p+p; if (q<tot) and (s[q].dig<s[q+1].dig) then inc(q); if (q>tot) or (s[q].dig<d) then begin s[p].id:=i;s[p].dig:=d;exit; end; s[p]:=s[q];p:=q; end; end; procedure work; var temp :Tnode; i :integer; begin for i:=n div 2 downto 1 do sift(i,n); for i:=n downto 1 do begin temp:=s[i]; s[i]:=s[1]; s[1]:=temp; sift(1,i-1); end; end; procedure out; var i :integer; begin writeln(0); for i:=1 to n do writeln(s[i].id); writeln(0); end; BEGIN init; work; out; END. Re: What's wrong with my program?Please help me! Послано Yuan 15 мар 2002 11:32 what about this case: 0 0 3 5 1 1 4 2 2 -8 1 3 |
|
|