重叠矩阵计算

平面上有两个矩形,它们的边平行于直角坐标系的X轴或Y轴。对于每个矩形,我们给出它的一对相对顶点的坐标,请你编程算出两个矩形的交的面积。

#include<iostream>
#include<cmath>
using namespace std;
double max(double x1, double x2);
double min(double x1, double x2);
int main()
{
    double x1, y1, x2, y2, x3, y3, x4, y4, x01, x02, y01, y02;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    x01 = max(min(x1, x2), min(x3, x4));
    x02 = min(max(x1, x2), max(x3, x4));
    y01 = max(min(y1, y2), min(y3, y4));
    y02 = min(max(y1, y2), max(y3, y4));
    if (x01 < x02&&y01 < y02)
        printf("%.2f\n", abs(x01 - x02)*abs(y01 - y02));//输出保留两位小数 
    else
        printf("%.2f\n", 0);
    return 0;
}

double max(double x1, double x2) {
    return x1>x2 ? x1 : x2;
}
double min(double x1, double x2) {
    return x1>x2 ? x2 : x1;
}

 

posted @ 2019-02-01 20:05  Kiss_the_rain  阅读(620)  评论(0编辑  收藏  举报