UVa 1643 Angle and squares

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.