10382-watering grass

All about problems in Volume CIII. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

10382-watering grass

Postby ACslow » Tue Apr 05, 2011 4:30 pm

Code: Select all
var p,pi,t,len,n,w,i,tot:longint;
    l,r:array[0..10000]of double;
    now,max:double;
    flag:boolean;
procedure qsort(x,y:longint);
  var i,j:longint;
      k,temp:double;
  begin
    i:=x;j:=y;k:=l[(i+j) div 2];
    repeat
      while l[i]<k do inc(i);
      while l[j]>k do dec(j);
      if not (i>j) then begin
        temp:=l[i];l[i]:=l[j];l[j]:=temp;
        temp:=r[i];r[i]:=r[j];r[j]:=temp;
        inc(i);dec(j);
      end;
    until i>j;
    if x<j then qsort(x,j);
    if i<y then qsort(i,y);
  end;

begin
  while not eof do begin
    readln(n,len,w);
    t:=0;
    for i:=1 to n do begin
      readln(p,pi);
      if pi>w/2 then begin
        inc(t);
        l[t]:=p-sqrt(sqr(pi)-sqr(w/2));
        if l[t]<0 then l[t]:=0;
        r[t]:=p+sqrt(sqr(pi)-sqr(w/2));
        if r[t]>len then r[t]:=len;
        //writeln(l[t],' ',r[t]);
      end;
    end;
    qsort(1,t);
    now:=0;
    i:=1;
    tot:=0;
    flag:=true;
    while now<len do begin
      max:=0;
      while (l[i]<=now) and (i<=t) do begin
        if r[i]>max then max:=r[i];
        inc(i);
      end;
      if max=0 then begin
        writeln(-1);
        flag:=false;
        break;
      end;
      now:=max;
      inc(tot);
    end;
    if flag then writeln(tot);
  end;
end.


I test many cases,and it's no problem.But online-judge says "runtime error".I check the program over and over again,but i still can not find any mistake.could you help me?
ACslow
New poster
 
Posts: 1
Joined: Tue Apr 05, 2011 4:23 pm

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 1 guest