View Code of Problem 106

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	float x1,x2,y1,y2;
	float r;
	while(cin >>x1>>y1>>x2>>y2>>r){
		float d=sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
		if(d==0){
			cout << "重合"<<endl; 
			continue;
		}
		if(d==2*r){
			cout << "相切"<<endl;
			continue; 
		}
		if(d>2*r){
			cout << "相离"<<endl;
			continue; 
		}
		if(d<2*r){
			cout << "相交"<<" "; 
			float ang1=acos((d*d)/(2*r*d));
			float ang2=acos((d*d)/(2*r*d));
			
			float area=ang1*r*r+ang2*r*r-r*d*sin(ang1);
			cout <<fixed<<setprecision(2)<<area<<endl;
		}
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 106