title: basic exercises rectangular area cross
categories:
- ACM
- Line post
tags: - n-dimensional deposit
date: 2020-03-14 16:16:17
If a determined length of the line segment intersects with another line segment, then the starting point is the maximum of the two segments starting point, the end point is the end point of the minimum of two segments. Then determine what the end point is not better than the starting point of a large, if the end is smaller than the starting point, then do not intersect. But because we usually do not know the beginning and end of the line, so to compare. So this method can be extended to n-dimensional.
problem
Questions basic exercises rectangular area post
Resource constraints
Time limit: 1.0s Memory Limit: 512.0MB
Problem Description
With two rectangular plane, their edges parallel to the X-axis or Y-axis of the rectangular coordinate system. For each rectangle, we give it the coordinates of a pair of opposite vertices, you calculate the area of programming post two rectangles.
Input Format
It contains only two input lines, with each line describing a rectangle.
In each row, are given opposite vertices of a pair of rectangular coordinates, with the coordinates of each point are two real absolute value is not more than 10 ^ 7 FIG.
Output Format
Output includes only a real number, is the area of the post, retained to two decimal places.
Sample input
1 1 3 3
2 2 4 4
Sample Output
1.00
algorithm
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){
double a[8];
for(int i=0;i<8;i++)
cin>>a[i];
double xmin=max(min(a[0],a[2]),min(a[4],a[6]));
double xmax=min(max(a[0],a[2]),max(a[4],a[6]));
double ymin=max(min(a[1],a[3]),min(a[5],a[7]));
double ymax=min(max(a[1],a[3]),max(a[5],a[7]));
if(xmin<xmax&&ymin<ymax)
printf("%.2f",(xmax-xmin)*(ymax-ymin));
else
cout<<"0.00";
}