Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define db long double
- #define x first
- #define y second
- #define mp make_pair
- #define pb push_back
- #define all(a) a.begin(), a.end()
- using namespace std;
- const db EPS = 1e-8;
- const db PI = acos(-1);
- db get_angle(db a, db b, db c) {
- db top = a * a + b * b - c * c;
- db bot = 2 * a * b;
- return acos(top / bot);
- }
- db area(db xa, db ya, db ra, db xb, db yb, db rb) {
- if (ra < rb) {
- swap(xa, xb);
- swap(ya, yb);
- swap(ra, rb);
- }
- db d = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
- if (d + EPS > ra + rb) {
- return 0;
- }
- if (ra + EPS > d + rb) {
- return PI * rb * rb;
- }
- db res = 0;
- db alp = 2 * get_angle(ra, d, rb);
- res += alp * ra * ra;
- res -= 0.5 * ra * ra * abs(sin(alp));
- cout << d << " " << ra << "\n";
- if (d + EPS > ra) {
- db beta = 2 * get_angle(rb, d, ra);
- res += beta * rb * rb;
- res -= 0.5 * rb * rb * abs(sin(beta));
- } else {
- db beta = 2 * PI - 2 * get_angle(d, rb, ra);
- res -= beta * rb * rb;
- res += 0.5 * rb * rb * abs(sin(beta));
- }
- return res;
- }
- void solve() {
- int r, R;
- cin >> r >> R;
- int xa, ya, ra, Ra, xb, yb, rb, Rb;
- cin >> xa >> ya >> xb >> yb;
- ra = r, rb = r;
- Ra = R, Rb = R;
- db res = area(xa, ya, Ra, xb, yb, Rb);
- res -= area(xa, ya, ra, xb, yb, Rb);
- res -= area(xa, ya, Ra, xb, yb, rb);
- res += area(xa, ya, ra, xb, yb, rb);
- cout.precision(20);
- cout << res << "\n";
- }
- int main(){
- #ifdef LOCAL
- freopen("M_input.txt", "r", stdin);
- //freopen("M_output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- for (int i = 0; i < t; i++) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement