Advertisement
Saleh127

Lo 1062

Aug 14th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. double x,y,h,lo,hi,midd,ans;
  4. double bisection(double mid)
  5. {
  6. double h1=sqrt((x*x)-(mid*mid));
  7. double h2=sqrt((y*y)-(mid*mid));
  8. double xx=(h1*h2)/(h1+h2);
  9. return xx;
  10. }
  11.  
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);cout.tie(0);
  16.  
  17. int t,i,j;
  18. scanf("%d",&t);
  19. for(i=1;i<=t;i++)
  20. {
  21. scanf("%lf %lf %lf",&x,&y,&h);
  22. lo=0.00;
  23. hi=min(x,y);
  24. j=32;
  25. while(j--)
  26. {
  27. midd=(lo+hi)/2;
  28. ans=bisection(midd);
  29. if(ans==h)
  30. {
  31. break;
  32. }
  33. else if(ans>h)
  34. {
  35. lo=midd;
  36. }
  37. else hi=midd;
  38. }
  39. printf("Case %d: %.10lf\n",i,midd);
  40. }
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement