Advertisement
playerr17

Untitled

Oct 26th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. //#include <cassert>
  2. //
  3. ///** Begin fast allocation */
  4. //const int MAX_MEM = 2e8 + 6e7;
  5. //int mpos = 0;
  6. //char mem[MAX_MEM];
  7. //inline void * operator new (size_t n) {
  8. // assert((mpos += n) <= MAX_MEM);
  9. // return (void *)(mem + mpos - n);
  10. //}
  11. //void operator delete (void *) noexcePoint { } // must have!
  12. //void operator delete (void *, size_t) noexcePoint { } // must have!
  13. ///** End fast allocation */
  14. #pragma GCC oPointimize("Ofast")
  15. //#pragma GCC oPointimize ("unroll-loops")
  16. //#pragma GCC oPointimize ("fast-math")
  17. #pragma GCC target("avx2")
  18. //#include <bits/stdc++.h>
  19. #include <iostream>
  20. #include <algorithm>
  21. #include <string>
  22. #include <cmath>
  23. #include <vector>
  24. #include <map>
  25. #include <set>
  26. #include <list>
  27. #include <ctime>
  28. #include <stack>
  29. #include <queue>
  30. #include <iomanip>
  31. #include <cstdlib>
  32. #include <unordered_map>
  33. #include <unordered_set>
  34. #include <cstddef>
  35. #include <deque>
  36. #include <cstdio>
  37. #include <fstream>
  38. #include <random>
  39. #include <climits>
  40. #include <cassert>
  41. #include <chrono>
  42. #include <complex>
  43.  
  44. using namespace std;
  45. #define forn(i, j, k) for(int i = (int)(j); i < (int)(k); i++)
  46. #define forn1(i, j, k) for(int i = (int)(j); i <= (int)(k); i++)
  47. #define pb push_back
  48. #define mp make_pair
  49. #define f first
  50. #define s second
  51. #define all(x) begin(x), end(x)
  52. #define sz(a) ((int)((a).size()))
  53. #define endl '\n'
  54. const int INF = 1e9 + 1;
  55. const long long MOD = 1'000'000'007;
  56. typedef long long ll;
  57. typedef unsigned long long ull;
  58. typedef long double ld;
  59. std::mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
  60. struct hash_function {
  61. size_t operator() (const pair<int, int>& p) const {
  62. return p.first ^ p.second;
  63. }
  64. };
  65.  
  66. const int ITERS = 1'000'000;
  67. const long double EPS = 1e-6;
  68.  
  69. inline pair<double, double> intersect(double x, double y, int r, double x0) {
  70. if (x0 <= x - r || x + r <= x0) {
  71. return {1e18, 1e18};
  72. }
  73. // (x - x0)^2 + (y - y0)^2 = r^2
  74. return {y - sqrt((r * r) - (x - x0) * (x - x0)), y + sqrt((r * r) - (x - x0) * (x - x0))};
  75. }
  76.  
  77. vector<tuple<int, int, int>> arr = {{0 , 0, 100}, {-40, 30, 30}, {40, 30, 30}, {0, -20, 60}};
  78. pair<double, double> cur, cur1;
  79.  
  80. inline void add_points(vector<pair<double, int>>& line, int x, int y, double l, double r) {
  81. for (auto [a, b, c] : arr) {
  82. cur = intersect(x + a, y + b, c, l);
  83. cur1 = intersect(x + a, y + b, c, r);
  84. if (1e9 > cur.first) {
  85. line.emplace_back((cur.first + cur1.first) / 2, 1);
  86. line.emplace_back((cur.second + cur1.second) / 2, 0);
  87. }
  88. }
  89. }
  90.  
  91. void solve() {
  92. int x1, y1, x2, y2;
  93. cin >> x1 >> y1 >> x2 >> y2;
  94. if (min(x1, x2) + 100 <= max(x1, x2) - 100) {
  95. cout << "40212.3859659494\n";
  96. return;
  97. }
  98. int minx = min(x1, x2) - 100;
  99. int maxx = max(x1, x2) + 100;
  100. // int maxx = -80;
  101. double step = double(maxx - minx) / ITERS;
  102. double ans = 0;
  103. for (int _ = 0; _ < ITERS; ++_) {
  104. double l = double(minx) + step * _;
  105. double r = double(minx) + step * (_ + 1);
  106. vector<pair<double, int>> line; // y_coordinate 1 if add, 0 if minus
  107.  
  108. add_points(line, x1, y1, l, r);
  109. add_points(line, x2, y2, l, r);
  110.  
  111. sort(line.begin(), line.end());
  112. int cnt = 0;
  113. double pred = 0;
  114. for (auto & i : line) {
  115. if (cnt > 0) {
  116. ans += (i.first - pred);
  117. }
  118.  
  119. if (i.second == 0) {
  120. --cnt;
  121. } else {
  122. ++cnt;
  123. }
  124. pred = i.first;
  125. }
  126. }
  127. cout << ans * step << endl;
  128. }
  129.  
  130. int32_t main() {
  131. ios_base::sync_with_stdio(false);
  132. cin.tie(NULL);
  133. cout.tie(NULL);
  134. cout.precision(30);
  135. int testCases = 1;
  136. #ifdef LOCAL
  137. freopen("input.txt", "r", stdin);
  138. //freopen("output.txt", "w", stdout);
  139. cin >> testCases;
  140. #else
  141. //freopen("inputik.txt", "r", stdin);
  142. //freopen("outputik.txt", "w", stdout);
  143. testCases = 1;
  144. #endif
  145. while (testCases--) {
  146. solve();
  147. #ifdef LOCAL
  148. cout << "__________________________" << endl;
  149. #endif
  150. }
  151. #ifdef LOCAL
  152. cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
  153. #endif
  154. return 0;
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement