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 if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)==2*r)cout<<"相切"<<endl;
		else if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)>2*r)cout<<"相离"<<endl;
		else {
			double d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));//这不知道圆重叠面积公式就没法写了呀 
			cout<<"相交 ";
			double a;
			double o=acos(0.5*d/r);
			a=(0.5*o*r*r)*2;
			a=a-sqrt(r*r-d*d/4)*d/2;
			a=a*2;
			cout<<setiosflags(ios::fixed)<<setprecision(2)<<a<<endl;
			
	}
	}
}

Double click to view unformatted code.


Back to problem 106