Angle and Squares UVA - 1643
程序员文章站
2022-03-02 10:21:54
...
题意:第一象限里有一个角,把n(n<=10)个给定边长的正方形摆在这个角里,使得阴影部分面积最大
思路:参考链接
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
const int maxn = 10 + 2;
int main()
{
int n;
while(scanf("%d",&n) && n)
{
double x,ax,ay,bx,by;
double l = 0,ans = 0;
scanf("%lf%lf%lf%lf",&bx,&by,&ax,&ay);
double k1 = ay / ax;
double k2 = by / bx;
if(k1 > k2) swap(k1,k2);
for(int i = 0;i < n;i++)
{
scanf("%lf",&x);
l += x;
ans -= x * x / 2;
}
ax = (1 + k2) * l / (k2 - k1),ay = k1 * ax;
bx = (1 + k1) * l / (k2 - k1),by = k2 * bx;
ans += (ax * by - bx * ay) / 2;
printf("%.3f\n",ans);
}
return 0;
}