zoukankan      html  css  js  c++  java
  • SDNU 1477.矩形面积交(思维)

    Description

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

    Input

       输入仅包含两行,每行描述一个矩形。   

            在每行中,给出矩形的一对相对顶点的坐标,每个点的坐标都用两个绝对值不超过10^7的实数表示。

    Output

       输出仅包含一个实数,为交的面积,保留到小数后两位。

    Sample Input

    1  1  3  3 
    2  2  4  4

    Sample Output

    1.00 
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <map>
    using namespace std;
    
    #define ll long long
    #define eps 1e-9
    
    const int inf = 0x3f3f3f3f;
    const int mod = 1e9+7;
    
    struct node
    {
        double x1, x2, y1, y2;
    }matrix[10];
    
    int main()
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &matrix[0].x1, &matrix[0].y1, &matrix[0].x2, &matrix[0].y2, &matrix[1].x1, &matrix[1].y1, &matrix[1].x2, &matrix[1].y2);
        double max_x1 = max(min(matrix[0].x1, matrix[0].x2), min(matrix[1].x1, matrix[1].x2));///交集区域的左下角
        double max_y1 = max(min(matrix[0].y1, matrix[0].y2), min(matrix[1].y1, matrix[1].y2));///交集区域的左下角
        double min_x1 = min(max(matrix[0].x1, matrix[0].x2), max(matrix[1].x1, matrix[1].x2));///交集区域的右上角
        double min_y1 = min(max(matrix[0].y1, matrix[0].y2), max(matrix[1].y1, matrix[1].y2));///交集区域的右上角
        if(min_x1 > max_x1 && min_y1 > max_y1)
            printf("%.2f
    ", (min_x1 - max_x1) * (min_y1 - max_y1));
        else///如果两个矩形无交集
            printf("0.00
    ");
        return 0;
    }
  • 相关阅读:
    【转载】线程数究竟设多少合理
    【转载】lvs为何不能完全替代DNS轮询
    接口测试考虑点
    隐式等待的两种写法
    邮件的操作
    Python列表排序 reverse、sort、sorted 操作方法
    兼容和适配的区别
    文件操作-oracle数据库
    初试线程-文件操作
    Selenium Grid分布式测试入门笔记
  • 原文地址:https://www.cnblogs.com/RootVount/p/11342202.html
Copyright © 2011-2022 走看看