View Code of Problem 106

#include<stdio.h>
#include<math.h>
#define PI 3.14159

int main(){
	double x1,y1,x2,y2,r;
	while(scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r)!=EOF){
		double d;
		d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		if(d>2*r){
			printf("相离\n");
		}
		else if(d==2*r){
			printf("相切\n");
		}
		else if(d<2*r&&d>0){
			double a,s;
			a=acos(d/(2*r));
			s=4*(PI*r*r*a/(2*PI)-0.5*r*d/2*sin(a));
			printf("相交 %.2lf\n",s); 
		}
		else if(d==0){
			printf("重合\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 106