View Code of Problem 106

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	double x1,y1,x2,y2,r;
	while(~scanf("%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&r)){
		double s1;
		s1 = sqrt(pow((x1-x2),2) + pow((y1-y2),2));
		if(x1 == x2 && y1 == y2)printf("重合\n");
		else if(s1 == 2*r)printf("相切\n");
		else if(s1 > 2*r)printf("相离\n");
		else{
			double jiao = acos((r * r + s1 * s1 - r * r) / (2 * r * s1));
			double S = jiao * r * r * 2;
			double si = r * s1 * sin(jiao); 
			printf("相交 %.2lf\n",S - si);
		} 
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 106