View Code of Problem 106

#include<bits/stdc++.h>
using namespace std;
#define pie 3.1415926

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

Double click to view unformatted code.


Back to problem 106