Problem Description
Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .
 
Input
Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).
 
Output
Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.
 
Sample Input
1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00
5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
 
Sample Output
1.00
56.25
  1. #include <cstdio>
  2. double max(double a,double b)
  3. {
  4. return (a>b)?a:b;
  5. }
  6. double min(double a,double b)
  7. {
  8. return (a<b)?a:b;
  9. }
  10. void fun(double &a,double &b)
  11. {
  12. double t;
  13. t=a;a=b;b=t;
  14. }
  15. int main()
  16. {
  17. double x1,y1,x2,y2,x3,y3,x4,y4;
  18. while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4))
  19. {
  20. //规范对角线坐标,对角线是从左下到右上,
  21. if(x1>x2) fun(x1,x2);
  22. if(y1>y2) fun(y1,y2);
  23. if(x3>x4) fun(x3,x4);
  24. if(y3>y4) fun(y3,y4);
  25.  
  26. //如果条件不能构成相交矩阵
  27. if(x1>=x4 || x2<=x3 || y1>=y4 || y2<=y3)
  28. {
  29. printf("%.2lf\n",);
  30. }
  31. else
  32. {
  33. //构造相交矩阵的对角线坐标(x1,y1),(x2,y2)
  34. //相交矩形的对角线坐标能够确定
  35. x1=max(x1,x3);
  36. y1=max(y1,y3);
  37. x2=min(x2,x4);
  38. y2=min(y2,y4);
  39. printf("%.2lf\n",(x2-x1)*(y2-y1));
  40. }
  41. }
  42. return ;
  43. }

HDU_2056——相交矩形的面积的更多相关文章

  1. TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)

    描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...

  2. PHP图形计算器(计算三角形矩形周长面积)

    运用PHP面向对象的知识设计一个图形计算器,同时也运用到了抽象类知识,这个计算器可以计算三角形的周长和面积以及矩形的周长和面积.本图形计算器有4个页面:1.PHP图形计算器主页index.php;   ...

  3. Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标

    题意 :给出一个初始的黑白相间的棋盘  有两个人  第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...

  4. HDU1255 扫描线 矩形交面积 离散化

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. 一条长为L的绳子,一面靠墙,另外三边组成矩形,问此矩形最大面积能是多少?

    靠墙的两边设为x,墙的对边设为y,有2x+y=L; 则y=L-2x, 矩形面积函数为xy=x(L-2x)=-2x2+xL,即f(x)=-2x2+xL 这时就是求二次函数的极值问题了. 按二次函数y=a ...

  6. maximal-rectangle——找出最大矩形的面积

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  7. HDU1255 覆盖的面积 —— 求矩形交面积 线段树 + 扫描线 + 离散化

    题目链接:https://vjudge.net/problem/HDU-1255 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<= ...

  8. Python 实现两个矩形重合面积

    计算两个矩形的重合面积 import math x1, y1, x2, y2 = input().split(" ") x1, y1, x2, y2=int(x1), int(y1 ...

  9. Objectarx 相交矩形求并集 面域转多段线

    测试结果: 主要思路:拾取一个点作为矩形的插入点,分别以该点进行两次jig操作,就能得到白色的两个相交的polyline,之后需要变成红色的封闭多段线.做法就是:求出两个白色矩形的面域,然后通过boo ...

随机推荐

  1. Cobar是提供关系型数据库(MySQL)分布式服务的中间件

    简介 Cobar是提供关系型数据库(MySQL)分布式服务的中间件,它可以让传统的数据库得到良好的线性扩展,并看上去还是一个数据库,对应用保持透明. 产品在阿里巴巴稳定运行3年以上. 接管了3000+ ...

  2. [转] 深入剖析 linux GCC 4.4 的 STL string

    本文通过研究STL源码来剖析C++中标准模板块库std::string运行机理,重点研究了其中的引用计数和Copy-On-Write技术. 平台:x86_64-redhat-linux gcc ver ...

  3. Java基础知识强化91:DateFormat类之DateFormat实现日期和字符串的相互转换

    1. DateFormat类概述: DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. 是抽象类,所以使用其子类SimpleDateFormat 2.  ...

  4. Java设计模式---组合模式

    一.组合模式定义 组合模式定义: Compose objects into tree structures to represent part-whole hierarchies. Composite ...

  5. ado.net(1)

    connection对象处于最顶层,是所有数据请求的关口 数据库连接过程 SqlConnection theConnection = new SqlConnection(); //创建一个connec ...

  6. 小学生之浅谈Struts2与struts1的运行机制

    Struts1工作原理图: 1.初始化:struts框架的总控制器ActionServlet是一个Servlet,它在web.xml中配置成自动启动的Servlet,在启动时总控制器会读取配置文件(s ...

  7. memcache锁,解决查询过多email查询为空的问题

    /* 设置memcache锁,解决查询过多email查询为空的问题 Begin */ $mmc = new Memcache; $mmc->connect('127.0.0.1', 11211) ...

  8. 关于操作DC时的资源泄露

    首先应明确一个概念 句柄, 关于句柄的详细介绍请见这里 对于句柄的使用小结:借来的要归还,创建的要释放,选出的要选入[尤其是针对GDI的一些句柄而言,如HPEN,HBRUSH等] 1. 使用GetDC ...

  9. 在QT中使用Irrlicht引擎的方法与步骤

      Ø 相关库,插件安装部分 本篇文档介绍在Qt5.2.0下面使用lrrlicht引擎在Qt窗口中输出(开发环境:vs2012) 1. 首先安装好Qt5.2.0,下载地址: http://downlo ...

  10. 逆波兰表达式 java

    描述  逆波兰表达式是一种把运算符前置的算术表达式,例如普通的表达式2 + 3的逆波兰表示法为+ 2 3.逆波兰表达式的优点是运算符之间不必有优先级关系, 也不必用括号改变运算次序,例如(2 + 3) ...