HDU2056 rectangles "rectangular area intersection"

Source: Internet
Author: User

RectanglesTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 15950 Accepted Submission (s): 5104

Problem Descriptiongiven-rectangles and the coordinates of the points on the diagonals of each rectangle,you has to C Alculate the area of the intersected part of the rectangles. Its sides is parallel to OX and OY.
Inputinput the first line of input was 8 positive numbers which indicate the coordinates of four points that must being on EAC H Diagonal. The 8 numbers is x1,y1,x2,y2,x3,y3,x4,y4. That means the points on the first rectangle is (x1,y1), (x2,y2); the other and the points on the second rectangle is (x3,y 3), (X4,Y4).
Outputoutput for each case output, the area of their intersected part, a single line.accurate up to 2 decimal places.
Sample Input
1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.005.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50

Sample Output
1.0056.25
find the upper and lower right coordinates of the overlapping rectangles, the code is a bit messy

#include <stdio.h> #include <math.h>struct Node {double x1, y1, x2, y2;} p1, P2;double min (double A, double b) {return a < b? A:b;} Double Max (double A, double b) {return a > b a:b;} void Swap (double& A, double& b) {Double t = A; a = b; b = t;} int main () {freopen ("Stdin.txt", "R", stdin);d ouble x1, y1, x2, Y2;while (scanf ("%lf%lf%lf%lf%lf%lf%lf%lf", &p1.x1, & Amp;p1.y1, &p1.x2, &p1.y2, &p2.x1, &p2.y1, &p2.x2, &p2.y2)! = EOF) {x1 = min (p1.x1, p1.x2); x2 = ma X (p1.x1, p1.x2); y1 = min (p1.y1, p1.y2); y2 = max (p1.y1, p1.y2);p 1.x1 = X1;p1.y1 = y1;p1.x2 = X2;p1.y2 = y2;x1 = Min (p2.x1,  P2.X2); x2 = max (p2.x1, p2.x2); y1 = min (p2.y1, p2.y2); y2 = max (p2.y1, p2.y2);p 2.x1 = X1;p2.y1 = y1;p2.x2 = X2;p2.y2 = y2;x1  = Max (p1.x1, p2.x1); y1 = max (p1.y1, p2.y1); x2 = min (p1.x2, p2.x2); y2 = min (p1.y2, p2.y2);p rintf ("%.2lf\n", x1 >= x2 | | Y1 >= y2? 0.0: (X2-X1) * (y2-y1));} return 0;}


HDU2056 rectangles "rectangular area intersection"

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.