题意:
      给你两个矩形,问你他们的重叠面积是多少。
思路:

     这两个矩形是平行x和y轴的,所以水题,不解释。


#include<stdio.h>

typedef struct
{
    double x ,y;
}NODE;

NODE a ,b ,c ,d;

int main ()
{
    double x1 ,x2 ,y1 ,y2;
    double x11 ,x22 ,y11 ,y22;
    while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf" ,&a.x ,&a.y ,&b.x ,&b.y ,&c.x ,&c.y ,&d.x ,&d.y))
    {
        x1 = x11 = 1000000000.0 ,x2 = x22 = 0;
        y1 = y11 = 1000000000.0 ,y2 = y22 = 0;
        x1 = a.x < b.x ? a.x : b.x;
        x2 = a.x > b.x ? a.x : b.x;
        y1 = a.y < b.y ? a.y : b.y;
        y2 = a.y > b.y ? a.y : b.y;
        x11 = c.x < d.x ? c.x : d.x;
        x22 = c.x > d.x ? c.x : d.x;
        y11 = c.y < d.y ? c.y : d.y;
        y22 = c.y > d.y ? c.y : d.y;
        double x = x1 > x11 ? x1 : x11;
        double xx = x2 < x22 ? x2 : x22;
        double y = y1 > y11 ? y1 : y11;
        double yy = y2 < y22 ? y2 : y22;
        if(xx - x <= 0 || yy - y <= 0) puts("0.00");
        else printf("%.2lf\n" ,(xx - x) * (yy - y));
     }
     return 0;
}


相关文章:

  • 2022-12-23
  • 2021-08-31
  • 2021-07-11
  • 2021-06-12
  • 2021-12-16
  • 2021-09-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2020-03-18
  • 2021-08-15
  • 2021-12-08
相关资源
相似解决方案