uva 12301 - An Angular Puzzle

题意:如图,已知角ACB, CAE, EAB, CBD, DBA (in degrees), 求 DEA。


注意:在 Output 中,“If there is more than one solution, print "Multiple solutions"”这句话是迷惑你的,根本没有这种情况!

#include<iostream>
#include<iomanip>
#include<cmath>
#define pi (2.0*asin(1.0))

using namespace std;

typedef struct point
{
    double x,y;
    point(double xx=0,double yy=0):x(xx),y(yy){}
}vector;

vector operator - (point a,point b)
{
    return vector(a.x-b.x,a.y-b.y);
}
point operator + (point a,vector b)
{
    return point(a.x+b.x,a.y+b.y);
}
vector operator * (vector a,double b)
{
    return vector(a.x*b,a.y*b);
}
double dot(vector a,vector b)
{
    return a.x*b.x+a.y*b.y;
}
double len(vector a)
{
    return sqrt(dot(a,a));
}
double angle(vector a,vector b)
{
    return acos(dot(a,b)/len(a)/len(b));
}
double cross(vector a,vector b)
{
    return a.x*b.y-a.y*b.x;
}
vector rot(vector a,double rad)
{
    double c=cos(rad),s=sin(rad);
    return vector(a.x*c-a.y*s,a.x*s+a.y*c);
}
point inter(point p,vector v,point q,vector w)
{
    vector u=p-q;
    double t=cross(w,u)/cross(v,w);
    return p+v*t;
}

int main()
{
    double a,b,c,d,e,s;
    point pa,pb,pd,pe;
    pb.x=10;
    while(cin>>a>>b>>c>>d>>e)
    {
        s=a+b+c+d+e;
        if(s==0) break;
        else if(s!=180) cout<<"Impossible"<<endl;
        else
        {
            b*=pi/180;
            c*=pi/180;
            d*=pi/180;
            e*=pi/180;
            vector v=rot(pb-pa,b+c),w=rot(pb-pa,pi-d-e);
            pd=inter(pa,v,pb,rot(pb-pa,pi-e));
            pe=inter(pa,rot(pb-pa,c),pb,w);
            double x=angle(pe-pd,pe-pa)*180/pi;
            cout<<fixed<<setprecision(2)<<x<<endl;
        }
    }
    return 0;
}





你可能感兴趣的:(c,VC,uva,amp,ACM-ICPC)