An easy problem?! (For details, take all the facts into account)

Source: Internet
Author: User

http://poj.org/problem?id=2826An easy problem?!
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10505 Accepted: 1584

Description

It ' s raining outside. Farmer Johnson ' s bull Ben wants some rain to water his flowers. Ben Nails, wooden boards on the wall of his barn. Shown in the pictures below, the both boards on the wall just look like the other segments on the plane, as they has the same WI Dth.

Your mission is to calculate how much rain these the boards can collect.

Input

The first line contains the number of test cases.
Each test case consists of 8 integers not exceeding to absolute value, x1, y1, x2, y2, x3, y3, x4, y4. ( x1, y1), ( x2, y2) is the endpoints of one board, and ( x3, y3), ( x4, y4) is the endpoints of the other one.

Output

For each test case output a single line containing a real number with precision up to both decimal places-the amount of R Ain collected.

Sample Input

20 1 1 01 0 2 10 1 2 11 0 1 2

Sample Output

1.000.00

The answer: Determine how much water can be received, if the two straight lines can be water, the triangular area

Two vector point multiplication: A*b*coso = x1*y1+x2*y2 for 1: Calculate angle 2: Calculate projection
Two vector fork multiplication: A*b*sino = X1*y1-x2*y2 used for 1: Calculate area 2: Judge where the point is in the straight line, right-hand rule
The output of this problem should be noted, with g++ to the final output ans+eps;
Here's the code:
1#include <cmath>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 6 #defineN 1057 #defineEPS 1e-6//The precision is too small can cause error, the accuracy is too general to increase the computational capacity, weigh themselves8 structPoint {9     Doublex, y;Ten Point () {} OnePointDoubleXDoubley): x (x), Y (y) {} APointoperator+ (ConstPoint O)Const{ -         returnPoint (x+o.x, y+o.y); -     } thePointoperator- (ConstPoint O)Const{ -         returnPoint (x-o.x, yo.y); -     } -  +     Double operator* (ConstPoint O)Const{ -         returnx*o.y-o.x*y; +     } A  at     Double operator^ (ConstPoint O)Const{//Point Multiplication -         returnX*o.x + y*o.y; -     } -  -Pointoperator* (Const DoubleAConst{ -         returnPoint (a*x, A *y); in     } -  to     Doublelen2 () +     { -         returnX*x + y*y; the     } * }a, B, S, T; $ Panax Notoginseng Point- intersection (Point-A, point-B, point-C, point-D) - { the     DoubleT = ((d-a) * (C-A))/((B-A) * (D-c)); +     returnA + (b-a) *fabs (t); A } the  + intMain () - { $ Point A, B, C, D; $     intT; -scanf"%d", &T); -      while(t--) the     { -scanf"%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);Wuyiscanf"%lf%lf%lf%lf", &c.x, &c.y, &d.x, &d.y); the          -         if(Fabs (A.Y-B.Y) < EPS | | fabs (C.Y-D.Y) < EPS)//There are horizontal lines Wu         { -Puts"0.00"); About             Continue; $         } -          -         if(A.y <b.y) Swap (A, b); -         if(C.y <d.y) Swap (c, d); A          +         if(Fabs (B.Y-A.Y) * (d.x-c.x)-(D.Y-C.Y) * (b.x-a.x)) < EPS)//Two lines parallel the         { -Puts"0.00"); $             Continue; the         } the          the         if(((b-a) * (C-A)) * ((b-a) * (d-a)) >0|| ((d-c) * (A-C)) * ((D-C) * (B-C)) >0)//two line segments have no intersection at all the         { -Puts"0.00"); in             Continue; the         } thePoint P =intersection (A, B, C, d); AboutPoint up = Point (0,Ten);  the         if((a-p) * (UP)) * ((c-p) * (UP)) >0)//The part that collects rainwater is on the same side of the vertical line. the         { the             if((a-p) * (c-p) >0&& c.x-a.x>=-EPS) +             { -Puts"0.00"); the                 Continue;Bayi             } the             if((a-p) * (C-P) <0&& a.x-c.x>=-EPS) the             { -Puts"0.00"); -                 Continue; the             } the         } the Point T1, T2; theT1.y = T2.y =min (a.y, c.y); -t1.x = a.x + (b.x-a.x) * (T1.Y-A.Y)/(b.y-a.y); thet2.x = c.x + (d.x-c.x) * (T2.Y-C.Y)/(d.y-c.y); the         DoubleAns = fabs ((t1.x-t2.x) * (T1.Y-P.Y)/2.0); theprintf"%.2f\n", ans+eps);//control accuracy,94     } the     return 0; the}

An easy problem?! (For details, take all the facts into account)

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.