Advertisement
Niloy007

1043 - Triangle Partitioning

Jun 6th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. double a, b, c, A, B, C;
  5. double Ratio = 0;
  6.  
  7. double binarySearch(double low, double high) {
  8.     double result = 0;
  9.     int count = 70;
  10.     double mid;
  11.     while (count--) {
  12.         mid = (low + high) / 2.00;
  13.         a = mid;
  14.         b = (a / A) * B;
  15.         c = (a / A) * C;
  16.         double ADE = ((a + b + c) / 2.0);
  17.         double ABC = ((A + B + C) / 2.0);
  18.         double areaOne = sqrt(ADE * (ADE - a) * (ADE - b) * (ADE - c));
  19.         double areaTwo = sqrt(ABC * (ABC - A) * (ABC - B) * (ABC - C));
  20.         double BDEC = areaTwo - areaOne;
  21.         result = areaOne / BDEC;
  22.         if (result > Ratio) {
  23.             high = mid;
  24.         } else {
  25.             low = mid;
  26.         }
  27.     }
  28.     return mid;
  29. }
  30.  
  31. int main() {
  32.     int testCase;
  33.     cin >> testCase;
  34.     for (int i = 0; i < testCase; i++) {
  35.         cin >> A >> B >> C >> Ratio;
  36.         printf("Case %d: %.10lf\n", i + 1, binarySearch(0, A));
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement