Test instructions
, there are n squares and a corner (all in the first quadrant), so that these squares and this corner form a closed shaded area, the maximum value of the area of the shaded area.
Analysis:
Visually, when the diagonal of the n squares is on a straight line, the area of the enclosing area is the largest. (Though I'm not quite sure, =_=| |)
Set all square Bengchang and for the L,OA, ob two linear equations are: y = k1x y = k2x, set a (x1, k1x1), B (x2, k2x2), can list the equation:
, the solution, corresponding to get ab two point coordinates, with the cross product to calculate the area of the OAB and then subtract half of these square area is the answer.
1#include <cstdio>2#include <algorithm>3 4 struct Point5 {6 Doublex, y;7Point (Doublex=0,Doubley=0): X (x), Y (y) {}8 };9 Ten DoubleCross (Constpoint& A,Constpoint&B) One{returna.x*b.y-a.y*b.x;} A - intMain () - { the //freopen ("In.txt", "R", stdin); - intN; - while(SCANF ("%d", &n) = =1&&N) - { + Point A, B; - DoubleL =0, SubArea =0, L; +scanf"%LF%LF%LF%LF", &a.x, &a.y, &b.x, &b.y); A for(inti =0; I < n; ++i) at { -scanf"%LF", &l); -L + =l; -SubArea + = L * L/2; - } - DoubleK1 = a.y/a.x, K2 = B.Y/b.x; in if(K1 >K2) Std::swap (K1, K2); - DoubleX1 = (k1+1) *l/(k2-k1), y1 = K1 *X1; to Doublex2 = (k2+1) *l/(k2-k1), y2 = K2 *x2; +A = Point (x1, y1), B =Point (x2, y2); - DoubleAns = Cross (A, B)/2-SubArea; the *printf"%.3f\n", ans); $ }Panax Notoginseng - return 0; the}
code June
UVa 1643 Angle and squares