Home BOJ. Two Circles (7869)
Post
Cancel

BOJ. Two Circles (7869)

[Link] https://www.acmicpc.net/problem/7869


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
#include <cmath>
// #include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define command_param int argc, char *argv[]
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 2002;
const int INF = 987654321;

int n;

int main() {
  // FASTIO;
  cout << fixed;
  cout.precision(3);
  double x1, y1, r1, x2, y2, r2;
  cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
  double s = 0;
  double dis_sqr = pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2);
  if(dis_sqr >= pow(r1 + r2, 2)) {
    cout << 0.000;
    return 0;
  }
  if(dis_sqr <= pow(abs(r1 - r2), 2)) {
    cout << M_PI * pow(min(r1, r2), 2);
    return 0;
  }
  double deg1 = acos((dis_sqr + pow(r1, 2) - pow(r2, 2)) / (2*sqrt(dis_sqr)*r1));
  double deg2 = acos((dis_sqr + pow(r2, 2) - pow(r1, 2)) / (2*sqrt(dis_sqr)*r2));
  s+= pow(r1, 2) * deg1; // pow(p1, 2) * (2deg1) / 2;
  s+= pow(r2, 2) * deg2;
  s-=pow(r1, 2) * sin(2*deg1) / 2;
  s-=pow(r2, 2) * sin(2*deg2) / 2;
  cout << s;
  return 0;
}
This post is licensed under CC BY 4.0 by the author.