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;
    }
  • 相关阅读:
    第一课基础知识
    Linux基础命令
    IO&Process基础知识
    caffe-windows 运行matlab 接口的例子
    process 3d image using caffe
    caffe-windows配置 cuda6.5+vs2012
    cuda7.0安装windows+vs2012
    SGD步长
    Exercise: Convolutional Neural NetworkCNN的反向求导及练习
    Create sparse matrix:sparse
  • 原文地址:https://www.cnblogs.com/RootVount/p/11342202.html
Copyright © 2011-2022 走看看