Saleh127

Light OJ 1297

Sep 13th, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5.  
  6. double l,w;
  7.  
  8. double area(double x)
  9. {
  10. return (l-2*x)*(w-2*x)*x;
  11. }
  12.  
  13. int main()
  14. {
  15. ios_base::sync_with_stdio(0);
  16. cin.tie(0);cout.tie(0);
  17.  
  18. test
  19. {
  20. cin>>l>>w;
  21.  
  22. double lo,hi,m1,m2,ans=0.0,ans1,ans2;
  23.  
  24. lo=0.0;
  25. hi=min(l,w)/2.0;
  26.  
  27. while(lo<hi)
  28. {
  29. m1=lo+(hi-lo)/3.0;
  30. m2=hi-(hi-lo)/3.0;
  31.  
  32. ans1=area(m1);
  33. ans2=area(m2);
  34.  
  35. ans=max(ans,max(ans1,ans2));
  36.  
  37. if(ans2>=ans1)
  38. {
  39. lo=m1+0.000001;
  40. }
  41. else hi=m2-0.000001;
  42. }
  43.  
  44. cout<<"Case "<<cs<<": "<<fixed<<setprecision(12)<<ans<<endl;
  45.  
  46. }
  47.  
  48.  
  49. return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment