• 蓝桥杯 矩阵面积交


    Description

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

    Input

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

    Output

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

    Sample Input

    1 1 3 3
    2 2 4 4

    Sample Output

    1.00
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const int maxn=1e5+10;
    17 using namespace std;
    18 
    19 struct node
    20 {
    21     double x;
    22     double y;
    23     int num;
    24 }PT[5];
    25 
    26 int main()
    27 {
    28     #ifdef DEBUG
    29     freopen("sample.txt","r",stdin);
    30     #endif
    31 //    ios_base::sync_with_stdio(false);
    32 //    cin.tie(NULL);
    33     
    34     for(int i=1;i<=4;i++)
    35         scanf("%lf %lf",&PT[i].x,&PT[i].y);
    36     double ans=0;
    37     double x1=max(min(PT[1].x,PT[2].x),min(PT[3].x,PT[4].x));
    38     double x2=min(max(PT[1].x,PT[2].x),max(PT[3].x,PT[4].x));
    39     double y1=min(max(PT[1].y,PT[2].y),max(PT[3].y,PT[4].y));
    40     double y2=max(min(PT[1].y,PT[2].y),min(PT[3].y,PT[4].y));
    41     if(x1>=x2||y1<=y2) ans=0;
    42     else ans=((x2-x1)*(y1-y2));
    43     printf("%.2f
    ",ans);
    44     
    45     return 0;
    46 }

    -

  • 相关阅读:
    解释基于注解的切面实现?
    @Controller 注解?
    Spring由哪些模块组成?
    解释AOP模块 ?
    什么是Spring的依赖注入?
    自动装配有哪些局限性 ?
    在Spring框架中如何更有效地使用JDBC?
    @Autowired 注解?
    @Required 注解?
    解释AOP?
  • 原文地址:https://www.cnblogs.com/jiamian/p/12233054.html
Copyright © 2020-2023  润新知