【杭电100题】2080 夹角有多大II

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2080

#include <iostream>
#include "math.h"

using namespace std;

#define PI 3.14159265

double getTheta(double x, double y)
{
    double th;
    if(x==0)
        th=90;
    else if(y<0)
        th=atan2(y, x)*180/PI+360;
    else
        th=atan2(y, x)*180/PI;
    return th;
}

int main()
{
    int t;
    cin>>t;
    double x1,y1,x2,y2;
    while(t--)
    {
        cin>>x1>>y1>>x2>>y2;
        double th1=getTheta(x1,y1);
        double th2=getTheta(x2,y2);
        //cout<<th1<<endl<<th2<<endl;
        double th=th1-th2;
        if(th<-180)
            th=360+th;
        else if(th<0)
            th=-th;
        else if(th<180)
            th=th;
        else
            th=360-th;
        printf("%.2f\n",th);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41727666/article/details/88422258
今日推荐