UVA 1643(p343)----Angles and Squares

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
double xa,ya,xb,yb,k1,k2;
int main()
{
    int n;
    while(scanf("%d",&n)==1&&n)
    {
        double l=0.0,tmp=0.0,area;
        scanf("%lf%lf%lf%lf",&xa,&ya,&xb,&yb);
        for(int i=0;i<n;i++)
        {
            double x;
            scanf("%lf",&x);
            tmp+=x*x/2;
            l+=x;
        }
        k1=ya/xa;k2=yb/xb;
        if(k1<k2) swap(k1,k2);
        xa=l*(1+k2)/(k1-k2);
        ya=k1*xa;
        xb=l*(1+k1)/(k1-k2);
        yb=k2*xb;
        area=fabs(xa*yb-xb*ya)/2;
        printf("%.3lf\n",area-tmp);
    }
    return 0;
}

你可能感兴趣的:(UVA 1643(p343)----Angles and Squares)