|
|
back to boardCommon BoardProblem 1011 Can someone help me on this: --- I keep getting Wrong Answer, but I can pass the given test case: program pr1011_conductors; var sol : integer; pct1, pct2 : real; found : boolean; begin found:=false; sol:=0; read(pct1,pct2); while not found do begin inc(sol); if trunc(sol*pct1/100) <> trunc(sol*pct2/100) then found:=true; end; writeln(sol); end. Re: Problem 1011 The line "if trunc(...)<> trunc(...)" should be: "if trunc(...)<ceil(...)" Re: Problem 1011 > The line "if trunc(...)<> trunc(...)" should be: > "if trunc(...)<ceil(...)" I have tried but still got WA. I used 'floor' instead of 'ceil', since ceil could not pass the problem test case. Probably this problem can be answered only using C, not Pascal :(( --- program pr1011_conductors; uses math; var sol : integer; pct1, pct2 : real; found : boolean; begin found:=false; sol:=0; read(pct1,pct2); while not found do begin inc(sol); if (trunc(sol*pct1/100) < floor(sol*pct2/100)) then found:=true; end; writeln(sol); end. Re: Problem 1011 Piece of solution: eps=1E-7; " procedure Solve; var i,j:int; lo,hi:real; begin for i:=1 to 50000 do begin lo:=i*p; hi:=i*q; lo:=lo+eps; hi:=hi-eps; if trunc(lo)<trunc(hi) then begin ans:=i; exit; end; end; end; " procedure ReadData; var i,j:int; begin read(p); read(q); p:=p/100; q:=q/100; end; It can't be submitted ina C as well :( Re: Problem 1011 I got accepted when I used this piece. You are great! But one question - how is that constant eps 1E-7 computed? Re: Problem 1011 > I got accepted when I used this piece. You are great! But > one question - how is that constant eps 1E-7 computed? I got accepted too using this one, I think epsilon is small number for correction of real type. What I do not understand why it does not work if we use : if trunc(...) - trunc(....) < eps then ... why we use hi-eps and lo+eps Re: Problem 1011 Posted by Lin Zi 18 Oct 2001 15:10 Thank you,Mirzayanov Michael.how do you find this way to solve? |
|
|