Advertisement
Niloy007

Crossed Ladders

Mar 21st, 2021
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define Niloy
  3. #define int int64_t
  4. #define MAX 1000
  5. #define MOD 1e9
  6. #define pb push_back
  7. #define pairs pair<int, int>
  8. #define vi vector<int>
  9. #define vb vector<bool>
  10. #define vii vector<pairs>
  11. #define lb lower_bound
  12. #define ub upper_bound
  13. #define endl '\n'
  14. #define llu unsigned long long
  15. using namespace std;
  16. /* ----------------------------------------------------------------------------------- */
  17.  
  18. // Input/Output
  19. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  20. #define all(x) x.begin(), x.end();
  21.  
  22. // Fractional Number
  23. #define fraction()        cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
  24.  
  25. #define scan(a)           scanf("%lld", &a);
  26. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
  27. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
  28. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  29.  
  30. #define scanD(a)          scanf("%lf", &a);
  31. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
  32. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
  33. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
  34.  
  35.  
  36. #define print(a)           printf("%lld\n", a);
  37. #define print2(a, b)       printf("%lld %lld\n", a, b);
  38. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
  39. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
  40.  
  41. #define printD(a)          printf("%lf\n", a);
  42. #define printD2(a, b)      printf("%lf %lf\n", a, b);
  43. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
  44. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
  45. #define printTwoD(a)       printf("%.2lf\n", a);
  46.  
  47. // File I/O
  48. #define read(x)  freopen(x, "r", stdin);
  49. #define write(x) freopen(x, "w", stdout);
  50.  
  51. // Loops
  52. #define rep(i, a, n) for (int i = a; i < n; i++)
  53. #define REP(i, a, n) for (int i = a; i <= n; i++)
  54. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
  55. #define REV(i, n, a) for (int i = n; i >= a; i--)
  56. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  57. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  58. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  59.  
  60. /* ----------------------------------------------------------------------------------- */
  61.  
  62. #define Cases  cout << "Case " << ++Case << ": ";
  63. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  64. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  65.  
  66. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
  67. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  68. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  69.  
  70. /* ----------------------------------------------------------------------------------- */
  71.  
  72. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
  73. int lcm(int n, int m) { return n / gcd(n, m) * m; }
  74.  
  75. struct debugger {
  76.     typedef string::iterator si;
  77.     static void call(si it, si ed) {}
  78.     template<typename T, typename ... aT>
  79.     static void call(si it, si ed, T a, aT... rest) {
  80.         string b;
  81.         for(; *it!=','; ++it)
  82.             if(*it!=' ')
  83.                 b+=*it;
  84.         cout << b << "=" << a << " ";
  85.         call(++it, ed, rest...);
  86.     }
  87. };
  88.  
  89. /* ----------------------------------------------------------------------------------- */
  90. void input() {
  91. #ifdef Niloy
  92.     read("input.txt");  
  93.     write("output.txt");
  94. #endif
  95. }
  96.  
  97. /* ----------------------------------------------------------------------------------- */
  98.  
  99.  
  100. double bisection(double x, double y, double c) {
  101.     double l = 0, r = min(x, y);
  102.     double d;
  103.     rep(i, 0, 100) {
  104.         d = (l + r) / 2.0;
  105.         double h1 = sqrt((x * x) - (d * d));
  106.         double h2 = sqrt((y * y) - (d * d));
  107.  
  108.         double h = ((h1 * h2) / (h1 + h2));
  109.  
  110.         if (h < c) {
  111.             r = d;
  112.         } else {
  113.             l = d;
  114.         }
  115.     }
  116.     return d;
  117. }
  118.  
  119. void solve() {
  120.     double x, y, c;
  121.     scanD3(x, y, c);
  122.     double d = bisection(x, y, c);
  123.     fraction();
  124.     cout << d << endl;
  125. }
  126.  
  127. int32_t main() {
  128.     // input();
  129.     // fastInput;
  130.     // solve();
  131.  
  132.     __test {
  133.         Cases;
  134.         solve();
  135.     }
  136.  
  137.     // showTime;
  138.     return 0;
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement