Advertisement
Guest User

Untitled

a guest
Jan 13th, 2021
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #undef NDEBUG
  2. #ifdef SU1
  3. #define _GLIBCXX_DEBUG
  4. #endif
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #define forn(i, n) for (int i = 0; i < int(n); i++)
  9. #define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
  10. #define fore(i, l, r) for (int i = int(l); i < int(r); i++)
  11. #define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
  12. #define all(a) (a).begin(), (a).end()
  13. #define sz(a) int((a).size())
  14. #define pb(a) push_back(a)
  15. #define mp(x, y) make_pair((x), (y))
  16. #define x first
  17. #define y second
  18.  
  19. using namespace std;
  20.  
  21. typedef long long li;
  22. typedef long double ld;
  23. typedef pair<li, li> pt;
  24.  
  25. template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
  26. template<typename X> inline X sqr(const X& a) { return a * a; }
  27.  
  28. const int INF = int(1e9);
  29. const li INF64 = li(1e18);
  30. const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;
  31.  
  32. pt c[2];
  33. li r[2];
  34.  
  35. inline bool read() {
  36.     forn(i, 2) assert(cin >> c[i].x >> c[i].y >> r[i]);
  37.     return true;
  38. }
  39.  
  40. li sqd;
  41.  
  42. inline ld calc(int a, int b) {
  43.     ld cosa = ld(sqr(r[b]) + sqd - sqr(r[a])) / (ld(2) * r[b] * sqrtl(sqd));
  44.     cosa = max(ld(-1), min(ld(1), cosa));
  45.     ld sina = sqrt(max(ld(0), 1 - sqr(cosa)));
  46.     ld alpha = acosl(cosa);
  47.     ld segment = alpha * sqr(r[b]);
  48.     ld triang = sqr(r[b]) * sina * cosa;
  49.     cerr << "alpha=" << 2 * alpha << endl;
  50.     cerr << "triang=" << triang << endl;
  51.     return segment - triang;
  52. }
  53.  
  54. inline void solve() {
  55.     if (r[0] > r[1]) swap(c[0], c[1]), swap(r[0], r[1]);
  56.  
  57.     sqd = sqr(c[0].x - c[1].x) + sqr(c[0].y - c[1].y);
  58.  
  59.     if (sqd > sqr(r[0] + r[1])) {
  60.         cerr << "Not intersecting" << endl;
  61.         cout << ld(0) << endl;
  62.         return;
  63.     }
  64.  
  65.     if (sqd <= sqr(r[1] - r[0])) {
  66.         cerr << "Fully in" << endl;
  67.         cout << PI * sqr(ld(r[0])) << endl;
  68.         return;
  69.     }
  70.    
  71.     ld ans = 0;
  72.     ans += calc(0, 1);
  73.     ans += calc(1, 0);
  74.     cout << ans << endl;
  75. }
  76.  
  77. int main() {
  78. #ifdef SU1
  79.     assert(freopen("input.txt", "rt", stdin));
  80.     assert(freopen("output.txt", "wt", stdout));
  81. #endif
  82.    
  83.     cout << setprecision(10) << fixed;
  84.     cerr << setprecision(5) << fixed;
  85.  
  86.     while (read()) {
  87.         solve();
  88.         break;
  89.     }
  90.    
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement