UVA 1643 Angle and Squares

https://vjudge.net/problem/UVA-1643

#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    double x,y,k1,k2;
    double h,s,ans;
    while(scanf("%d",&n)!=EOF)
    {
        if(!n) return 0;
        scanf("%lf%lf",&x,&y);
        k1=y/x;
        scanf("%lf%lf",&x,&y);
        k2=y/x;
        if(k1<k2) swap(k1,k2);
        h=s=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&x);
            h+=x; s+=x*x;
        } 
        s/=2;
        ans=h*h/2-s+k2*h*h/2;
        x=(k2*h+h)/(k1-k2);
        ans+=x*k1*x/2-x*k2*x/2;
        printf("%.3lf
",ans);
    }
}
原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/7404573.html