ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1484. Film Rating

wa 17
Posted by tereshinvs 8 May 2010 12:19
{$N+}

var x, y, temp:extended;
    n, l, r, m, sum, res:extended;

function rnd(t:extended):extended;
begin
     if frac(t)>=0.5 then rnd:=trunc(t)+1
                     else rnd:=trunc(t);
end;

begin
     readln(x, y, n);
     l:=10; r:=10*n; x:=x*10; sum:=-1;
     while l<=r do begin
           m:=trunc((l+r)/2);
           temp:=rnd(m/n*10);
           if abs(temp-x)<10e-12 then begin
                                     sum:=m;
                                     l:=m+1;
                                     continue;
                                     end;
           if temp<x then l:=m+1
                     else r:=m-1;
           end;
     {writeln(sum:0:0);}
     if sum=-1 then begin
                    writeln('Impossible');
                    exit;
                    end;
     l:=0; r:=2000000000; res:=-1;
     while l<=r do begin
           m:=trunc((l+r)/2);
           temp:=(sum+m)/(n+m);
           if rnd(temp*10)<=y*10 then begin
                                      res:=m;
                                      r:=m-1;
                                      end
                                 else l:=m+1;
           end;
     if res=-1 then writeln('Impossible')
               else writeln(res:0:0);
end.