|  | 
|  | 
| back to board | Please give me some test Posted by Harmy  2 Jun 2004 14:50    Help!I use binary search to find the answer.Please give me some test! Thanks
 {my wrong mode here}
 const
 maxn=1000;
 maxm=1000000;
 var
 a1,n:longint;
 ta1:real;
 a:array[1..maxn]of extended;
 
 procedure init;
 begin
 {    assign(input,'1066.in'); reset(input);}
 readln(n,ta1);
 a1:=round(ta1*maxm);
 a[1]:=a1;
 end;
 
 procedure search(first,last:longint);
 var
 cha1,cha2:real;
 h,h1,h2:longint;
 
 function solve(x:longint):boolean;
 var
 te,i,j:longint;
 begin
 i:=2; a[2]:=x; solve:=true;
 repeat
 inc(i);
 a[i]:=2*(a[i-1]+maxm)-a[i-2];
 if a[i]<0
 then begin
 solve:=false; exit;
 end;
 until a[i]>a[i-1];
 dec(I);
 if first=last
 then begin
 for j:=i+1 to n do
 a[j]:=2*(a[j-1]+maxm)-a[j-2];
 writeln((a[n]/maxm):0:2);
 halt;
 end;
 end;
 
 begin
 h:=(first+last) div 2;
 if solve(h)
 then search(first,h)
 else search(h+1,last);
 end;
 
 begin
 init;
 search(0,a1);
 end.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 
 | 
|