View Code of Problem 106

#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main() {
	double x1, y1, x2, y2, r;
	while (cin >> x1 >> y1 >> x2 >> y2 >> r) {
		if (x1 == x2 && y1 == y2) {
			cout << "重合" << endl;
		}
		else {
			double d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
			if (d == 2 * r) {
				cout << "相切" << endl;
			}
			else if (d > 2 * r) {
				cout << "相离" << endl;
			}
			else if (d < 2 * r) {
				double a = acos(pow(d,2) / (2.0 * r * d));
				double s = 2 * a * pow(r, 2) - r * d * sin(a);
				cout << "相交 " << fixed << setprecision(2) << s << endl;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 106