LA 2402 (enum) fishnet

Source: Internet
Author: User

Test instructions

There are n points on the four boundaries of a square, dividing it into (n+1) 2 quads, and finding the maximum of the quadrilateral area.

Analysis:

Because n is small in size, you can double-loop the enumeration to find the maximum value.

To find the intersection point of a line (a, 0) (b, 0) and a straight line (0, C) (0, D), I am the solution of the two-tuple equation, and then we use the cross-product to find the area.

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 6 Const intMAXN = -+Ten;7 structHEHE8 {9     DoubleA, B, C, D;Ten }HEHE[MAXN]; One  A struct Point - { -     Doublex, y; thePoint (Doublex=0,Doubley=0): X (x), Y (y) {} - }; - typedef point Vector; -  +Vectoroperator- (Constvector& A,Constvector&B) -{returnVector (a.x-b.x, A.Y-b.y); } +  A DoubleCross (Constvector& A,Constvector&B) at{return(a.x*b.y-a.y*b.x); } -  -Point Getintersection (Const Double& A,Const Double& B,Const Double& C,Const Double&d) - { -     Doublex = (A + (B-A) *c)/(1-(B-A) * (dc)); -     Doubley = (d-c) *x+C; in     returnPoint (x, y); - } to  + intMainvoid) - { the     //freopen ("2402in.txt", "R", stdin); *      $     intN;Panax Notoginseng      while(SCANF ("%d", &n) = =1&&N) -     { thememset (hehe,0,sizeof(hehe)); +          for(inti =1; I <= N; ++i) scanf ("%LF", &hehe[i].a); A          for(inti =1; I <= N; ++i) scanf ("%LF", &hehe[i].b); the          for(inti =1; I <= N; ++i) scanf ("%LF", &hehe[i].c); +          for(inti =1; I <= N; ++i) scanf ("%LF", &hehe[i].d); -hehe[n+1].A = hehe[n+1].b = hehe[n+1].C = hehe[n+1].D =1.0; $          $         DoubleAns =0.0; -          for(inti =0; I <= N; ++i) -              for(intj =0; J <= N; ++j) the             { - Point A, B, C, D;WuyiA =getintersection (hehe[i].a, hehe[i].b, hehe[j].c, HEHE[J].D); theB = Getintersection (hehe[i+1].A, hehe[i+1].b, HEHE[J].C, HEHE[J].D); -C = Getintersection (hehe[i+1].A, hehe[i+1].B, hehe[j+1].C, hehe[j+1].d); WuD = Getintersection (hehe[i].a, hehe[i].b, hehe[j+1].C, hehe[j+1].d); -                 Doubletemp =0.0; Abouttemp + = Cross (b-a, c-a)/2; $temp + = Cross (c-a, d-a)/2; -Ans =Std::max (ans, temp); -             } -              Aprintf"%.6f\n", ans); +     } the      -     return 0; $}
code June

LA 2402 (enum) fishnet

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.