HDU2056(rectangles)

Rectangles

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19299    Accepted Submission(s): 6255

Problem Description

Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .

Input

Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).

Output

Output For each case output the area of their intersected part in 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.00
5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50

Sample Output

1.00
56.25

Author

seeyou

Source

校庆杯Warm Up

Recommend

linle   |   We have carefully selected several similar problems for you:  20572058206220602059

Statistic | Submit | Discuss | Note

这道题乍一看挺复杂,但是是有技巧的。只需要将4个横坐标和4个纵坐标排序然后就可简化成一种很容易计算的形式。还要注意首先要排除没有交叉部分的情况。

 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4
 5 int main()
 6 {
 7     double x[4], y[4];
 8     while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])) {
 9         double minx1 = min(x[0], x[1]), maxx1 = max(x[0], x[1]), minx2 = min(x[2], x[3]), maxx2 = max(x[2], x[3]);
10         double miny1 = min(y[0], y[1]), maxy1 = max(y[0], y[1]), miny2 = min(y[2], y[3]), maxy2 = max(y[2], y[3]);
11         if(minx1 >= maxx2 || maxx1 <= minx2 || maxy1 <= miny2 || miny1 >= maxy2) printf("%.2lf\n", 0);
12         else {
13             sort(x, x + 4);
14             sort(y, y + 4);
15             printf("%.2lf\n", (x[2] - x[1]) * (y[2] - y[1]));
16         }
17     }
18 }

时间: 2024-10-04 05:42:21

HDU2056(rectangles)的相关文章

HDU2056 Rectangles 【矩形面积交】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15950    Accepted Submission(s): 5104 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e

HDU2056 Rectangles【水题】【相交面积】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15823    Accepted Submission(s): 5061 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e

Project Euler 85 :Counting rectangles 数长方形

Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 contains eighteen rectangles: Although there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the

Axis&#173; Aligned ?Rectangles

Describe ?an? algorithm ?that ?takes ?an ?unsorted ?array ?of ?axis‐aligned ?rectangles ?and? returns ?any ?pair ?of ?rectangles ?that? overlaps,? if ?there? is ?such? a ?pair.? ?Axis‐aligned? means? that? all ?the? rectangle? sides? are ?either ?par

Find the total area covered by two rectilinear rectangles in a 2D plane. 208MM

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. pu

HDU 2056 Rectangles(计算相交面积)

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20183    Accepted Submission(s): 6537 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e

UVA 10574 - Counting Rectangles 计数

Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.InputThe ?rst line contains the number of tests t (1 ≤ t ≤ 10). Each case contains a single lin

第七届河南省赛H.Rectangles(lis)

10396: H.Rectangles Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 229  Solved: 33 [Submit][Status][Web Board] Description Given N (4 <= N <= 100)  rectangles and the lengths of their sides ( integers in the range 1..1,000), write a program that fi

ZOJ (狗狗)1426 Counting Rectangles(暴力)

Counting Rectangles Time Limit: 2 Seconds      Memory Limit: 65536 KB We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles formed by these segments. As an example,