hdu 2080 几何计算 水题 两线段的夹角 一个点是原点

注意平角,钝角的判定,其中主要是s=0.5*sin@*a*b 公式的运用

2
1 1 2 2
1 1 1 0

#include <stdio.h>
#include <math.h>

int main()
{
	double x1,y1,x2,y2,s,len1,len2,k;

	int t;

	scanf("%d",&t);

	while(t--)
	{
		scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);

		s=fabs(x1*y2-y1*x2);

		len1=sqrt(x1*x1+y1*y1);

		len2=sqrt(x2*x2+y2*y2);

		//printf("%.2lf %.2lf %.2lf %.2lf\n",asin(s/(len1*len2)),len1,len2,s);

		printf("%.2lf\n",(k=asin(s/(len1*len2))/acos(-1)*180)?x1*x2<=0&&1*y2<=0?180-k:k:x1*x2<0?180:0);
	}

	return 0;
}

  

原文地址:https://www.cnblogs.com/jackes/p/2434030.html