View Code of Problem 106

#include<stdio.h>
#include<math.h>
int main()
{
	int x1,x2,y1,y2;
	double r;
	while(scanf("%d %d %d %d %lf",&x1,&y1,&x2,&y2,&r)!=EOF)
	{
		if(x1==x2&&y1==y2)
		{
			printf("重合\n");
		}
		else
		{
			int x=x1-x2;
			int y=y1-y2;
			double l=sqrt(x*x-y*y);
			if(l>2*r)
			{
				printf("相离\n");
			}
			else if(l==2*r)
			{
				printf("相切\n");
			}
			else
			{
				double ang1=acos((r*r+l*l-r*r)/2*(l*r));
				double ang2=acos((r*r+l*l-r*r)/2*(l*r));
				double area=ang1*r*r*2-sin(ang1)*r*l;
				printf("相交 %.2lf\n",area);
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 106