Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Den ( 15 years ago )
#include <cstdio>
#include <cmath>

double a,b,c,l,len;


double f(double len){
 double ax,ay,bx,by,lenb,r;
 lenb=sqrt(l*l-len*len);
 ax=lenb-b;
 ay=0-a;

 bx=0-b;
 by=len-a;

 r=-1*(ax*by-ay*bx)/l;
 return r;

 
}
int main(){
 /*
 freopen("in.txt","rt",stdin);
 freopen("out.txt","wt",stdout);
 */
 scanf("%lf%lf%lf",&a,&b,&l);
 if((b-l>=0)){
  if((a-l>=0))
   printf("%.7lf",l);
  else
   printf("%.7lf",a);
  return 0;
 }

 double s=0,vs1,vs2,ans;
 double fin=l;
 ans=10000000;
 while (abs(f(fin)-ans)>0.0000001){
  vs1=f(s+(fin-s)/3);
  vs2=f(s+(fin-s)*2/3);
  if(vs2<=vs1)
   s=s+(fin-s)/3;
  else
   fin=s+(fin-s)*2/3;
  ans=f((s+fin)/2);
 }
 if(ans<0)
  printf("My poor head =(");
 else
  printf("%.7lf",ans);
 

}

 

Revise this Paste

Your Name: Code Language: