Niloy007

Expanding Rods

Mar 21st, 2021
689
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. double bisection(double l1, double L) {
  100.     double l = 0, r = 1e18;
  101.  
  102.     rep(i, 0, 100) {
  103.         double R = (l + r) / 2.0;
  104.  
  105.         double ans = R * (2.0 * asin(L / (2.0 * R)));
  106.         if (ans < l1) {
  107.             r = R;
  108.         } else {
  109.             l = R;
  110.         }
  111.     }
  112.     return l;
  113. }
  114.  
  115. void solve() {
  116.     double l, n, c;
  117.     scanD3(l, n, c);
  118.  
  119.     double l1 = (1 + (n * c)) * l;
  120.  
  121.     double R = bisection(l1, l);
  122.     double h = R - sqrt((R * R) - ((l / 2.0) * (l / 2.0)));
  123.  
  124.     fraction();
  125.     cout << h << endl;
  126. }
  127.  
  128. int32_t main() {
  129.     // input();
  130.     // fastInput;
  131.     // solve();
  132.  
  133.     __test {
  134.         Cases;
  135.         solve();
  136.     }
  137.  
  138.     // showTime;
  139.     return 0;
  140. }
  141.  
RAW Paste Data