Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- using ld = long double;
- const ld PI = acosl(-1.0);
- ld IntersectCircles(int r1, int r2, int x, int y) {
- ld dist = sqrtl(x * x + y * y);
- if (dist >= r1 + r2) return 0;
- if (r1 < r2) swap(r1, r2);
- if (dist + r2 <= r1) return PI * r2 * r2;
- ld cosA = (r1 * r1 + dist * dist - r2 * r2) * 0.5 / dist / r1;
- ld A = acosl(cosA);
- ld cosB = (r2 * r2 + dist * dist - r1 * r1) * 0.5 / dist / r2;
- ld B = acosl(cosB);
- ld firstAns = (A - sinl(A + A)) * r1 * r1;
- ld secondAns = (B - sinl(B + B)) * r2 * r2;
- return firstAns + secondAns;
- }
- ld IntersectCircles(int x1, int y1, int r1, int x2, int y2, int r2) {
- return IntersectCircles(r1, r2, x2 - x1, y2 - y1);
- }
- ld FindSegment(ld r, ld h) {
- h = abs(h);
- if (h >= r) return 0;
- ld cosA = h / r;
- ld A = acosl(cosA);
- return (PI - A) * r * r;
- }
- ld Case1(ld h, ld g, ld r) {
- ld a = sqrtl(r * r - g * g) - h;
- ld b = sqrtl(r * r - h * h) - g;
- ld ans = a * b / 2;
- ld c = sqrtl(a * a + b * b) / 2;
- ld d = sqrtl(r * r - c * c);
- return ans + FindSegment(r, d);
- }
- ld Do(int x, int y, int r) {
- const int R = 60;
- x = abs(x);
- ld ans = IntersectCircles(R, r, x, y);
- ld f = sqrtl(r * r - y * y);
- ld left = x - f;
- ld right = x + f;
- if (-R <= left && right <= R) {
- return ans - FindSegment(r, y);
- }
- left = 0;
- right = R;
- ld mid;
- ld a, b;
- ld up = 0;
- ld down = 0;
- for (int i = 0; i < 100; i++) {
- mid = (left + right) / 2;
- a = sqrtl(R * R - mid * mid);
- b = y + sqrtl(r * r - (x - mid) * (x - mid));
- if (a > b) {
- right = mid;
- } else {
- left = mid;
- }
- }
- up = mid;
- left = 0;
- right = R;
- for (int i = 0; i < 100; i++) {
- mid = (left + right) / 2;
- a = - sqrtl(R * R - mid * mid);
- b = - y - sqrtl(r * r - (x - mid) * (x - mid));
- if (a < b) {
- right = mid;
- } else {
- left = mid;
- }
- }
- down = mid;
- if (down > up) {
- ld sub = Case1(0, up, R) + Case1(x - up, 0 - y, r);
- ans -= sub;
- } else {
- ans = Case1(0, down, R) + Case1(x - down, 0 - y, r);
- }
- return ans;
- }
- ld IntersectCircleAndHalfOfCircle(int r1, int r2, int x, int y) {
- if (r1 < y) return IntersectCircles(r1, r2, x, y);
- if (y < -r1) return 0;
- ld dist = sqrtl(x * x + y * y);
- if (dist >= r1 + r2) return 0;
- if (r1 > r2) {
- if (dist + r2 <= r1) {
- return PI * r2 * r2 / 2;
- }
- }
- return Do(-x, -y, r1);
- }
- ld IntersectCircleAndHalfOfCircle(int x1, int y1, int r1, int x2, int y2, int r2) {
- return IntersectCircleAndHalfOfCircle(r1, r2, x2 - x1, y2 - y1);
- }
- ld IntersectHalfs(int x1, int y1, int r1, int x2, int y2, int r2) {
- return IntersectCircleAndHalfOfCircle(r2, r1, abs(x1 - x2), -abs(y1 - y2));
- }
- ld S(ld r) {
- return r * r * PI;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- x2 -= x1;
- y2 -= y1;
- x1 = y1 = 0;
- int Afirstx = x1 - 40;
- int Afirsty = y1 + 30;
- int Afirstr = 30;
- int Asecondx = x1 + 40;
- int Asecondy = y1 + 30;
- int Asecondr = 30;
- int Athirdx = x1;
- int Athirdy = y1 - 20;
- int Athirdr = 60;
- int Bfirstx = x2 - 40;
- int Bfirsty = y2 + 30;
- int Bfirstr = 30;
- int Bsecondx = x2 + 40;
- int Bsecondy = y2 + 30;
- int Bsecondr = 30;
- int Bthirdx = x2;
- int Bthirdy = y2 - 20;
- int Bthirdr = 60;
- ld ans = 0;
- ans += S(100) + S(100) - IntersectCircles(x1, y1, 100, x2, y2, 100);
- cout << ans << endl;
- ans -= S(Afirstr) - IntersectCircles(Afirstx, Afirsty, Afirstr, x2, y2, 100);
- ans -= S(Asecondr) - IntersectCircles(Asecondx, Asecondy, Asecondr, x2, y2, 100);
- ans -= S(Athirdr) / 2 - IntersectCircleAndHalfOfCircle(x2, y2, 100, Athirdx, Athirdy, Athirdr);
- cout << ans << endl;
- ans -= S(Bfirstr) - IntersectCircles(Bfirstx, Bfirsty, Bfirstr, x1, y1, 100);
- ans -= S(Bsecondr) - IntersectCircles(Bsecondx, Bsecondy, Bsecondr, x1, y1, 100);
- ans -= S(Bthirdr) / 2 - IntersectCircleAndHalfOfCircle(x1, y1, 100, Bthirdx, Bthirdy, Bthirdr);
- cout << ans << endl;
- ans -= IntersectCircles(Afirstx, Afirsty, Afirstr, Bfirstx, Bfirsty, Bfirstr);
- ans -= IntersectCircles(Afirstx, Afirsty, Afirstr, Bsecondx, Bsecondy, Bsecondr);
- ans -= IntersectCircleAndHalfOfCircle(Afirstx, Afirsty, Afirstr, Bthirdx, Bthirdy, Bthirdr);
- cout << ans << endl;
- ans -= IntersectCircles(Asecondx, Asecondy, Asecondr, Bfirstx, Bfirsty, Bfirstr);
- ans -= IntersectCircles(Asecondx, Asecondy, Asecondr, Bsecondx, Bsecondy, Bsecondr);
- ans -= IntersectCircleAndHalfOfCircle(Asecondx, Asecondy, Asecondr, Bthirdx, Bthirdy, Bthirdr);
- cout << ans << endl;
- ans -= IntersectCircleAndHalfOfCircle(Bfirstx, Bfirsty, Bfirstr, Athirdx, Athirdy, Athirdr);
- ans -= IntersectCircleAndHalfOfCircle(Bsecondx, Bsecondy, Bsecondr, Athirdx, Athirdy, Athirdr);
- ans -= IntersectHalfs(Bthirdx, Bthirdy, Bthirdr, Athirdx, Athirdy, Athirdr);
- cout << fixed << setprecision(15) << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement