BOJ 7869 두 원

1 개요[ | ]

BOJ 7869 두 원

2 C++[ | ]

#include <bits/stdc++.h>
using namespace std;
#define y1 _

double x1, y1, r1;
double x2, y2, r2;

double solve() {
    double d = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	if (r1 + r2 <= d) {
		return 0;
	}
	if (fabs(r1-r2) >= d) {
		return M_PI * fmin(r1*r1, r2*r2);
	}
	double t1 = acos((d*d + r1*r1 - r2*r2)/(d*r1*2)) * 2;
	double t2 = acos((d*d + r2*r2 - r1*r1)/(d*r2*2)) * 2;
    return (t1*r1*r1 + t2*r2*r2 - r1*r1*sin(t1) - r2*r2*sin(t2)) * 0.5;
}

int main() {
    cin >> x1 >> y1 >> r1;
    cin >> x2 >> y2 >> r2;
    cout << fixed;
    cout.precision(3);
    cout << solve();
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}