题目链接: tzc1200
方法:计算几何
代码:
#include <iostream>
#include <cmath>
using namespace std;
struct point {double x,y;};
struct line { point s,e; };
const double pi=acos(-1);
//求两条直线的角度
//返回角度为弧度制,并且以逆时针方向为正方向
double angle(line a,line b)
{
double dtheta,theta1,theta2;
a.s.x-=a.e.x;a.s.y-=a.e.y;
b.s.x-=b.e.x;b.s.y-=b.e.y;
theta1 = atan2(a.s.y,a.s.x);
theta2 = atan2(b.s.y,b.s.x);
dtheta = theta2 - theta1;
while (dtheta > pi)dtheta -= pi*2;
while (dtheta < -pi)dtheta += pi*2;
return(dtheta);
}
int main()
{
line a,b;
int t;
cin>>t;
while(t--)
{
cin>>a.s.x>>a.s.y>>a.e.x>>a.e.y;
cin>>b.s.x>>b.s.y>>b.e.x>>b.e.y;
double ans=angle(a,b)/pi*180;
if(ans<0)ans+=180;
if(ans>180)ans-=180;
if(ans>90)ans=180-ans;
printf("%.1lf\n",ans);
}
return 0;
}