描述
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.
Input
The input file consists of several test cases. Each test
case starts with a line containing a single integer n (1<=n<=100)
of available maps. The n following lines describe one map each. Each of
these lines contains four numbers x1;y1;x2;y2
(0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily
integers. The values (x1; y1) and (x2;y2) are the coordinates of the
top-left resp. bottom-right corner of the mapped area.

The input file is terminated by a line containing a single 0. Don’t process it.

 
Output
For each test case, your program should output one section.
The first line of each section must be “Test case #k”, where k is the
number of the test case (starting with 1). The second one must be “Total
explored area: a”, where a is the total explored area (i.e. the area of
the union of all rectangles in this test case), printed exact to two
digits to the right of the decimal point.

Output a blank line after each test case.

Sample Input
2
10 10 20 20
15 15 25 25.5
0
 
Sample Output
Test case #1
Total explored area: 180.00
题意
给你N个矩形,每个矩形的左下和右上的点,求面积并
题解
由于点不是很多,可以对x轴进行离散化,去重
线段树面积并
代码

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. const int N=;
  7.  
  8. int col[N<<];
  9. double sum[N<<],x[N<<];
  10.  
  11. struct seg
  12. {
  13. double l,r,h;
  14. int s;
  15. seg(){}
  16. seg(double l,double r,double h,int s):l(l),r(r),h(h),s(s){}
  17. bool operator<(const seg &D)const{
  18. return h<D.h;
  19. }
  20. }s[N];
  21. void PushUp(int rt,int l,int r)
  22. {
  23. if(col[rt])sum[rt]=x[r+]-x[l];
  24. else if(l==r)sum[rt]=;
  25. else sum[rt]=sum[rt<<]+sum[rt<<|];
  26. }
  27. void Update(int L,int R,int C,int l,int r,int rt)
  28. {
  29. if(L<=l&&r<=R)
  30. {
  31. col[rt]+=C;
  32. PushUp(rt,l,r);
  33. return;
  34. }
  35. int mid=(l+r)>>;
  36. if(L<=mid)Update(L,R,C,l,mid,rt<<);
  37. if(R>mid)Update(L,R,C,mid+,r,rt<<|);
  38. PushUp(rt,l,r);
  39. }
  40. int main()
  41. {
  42. int n,o=;
  43. double a,b,c,d;
  44. while(~scanf("%d",&n),n)
  45. {
  46. int cnt=;
  47. for(int i=;i<n;i++)
  48. {
  49. scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
  50. s[++cnt]=seg(a,c,b,);
  51. x[cnt]=a;
  52. s[++cnt]=seg(a,c,d,-);
  53. x[cnt]=c;
  54. }
  55. sort(x+,x++cnt);
  56. sort(s+,s++cnt);
  57. int k=;
  58. for(int i=;i<=cnt;i++)
  59. if(x[i]!=x[i-])
  60. x[++k]=x[i];
  61.  
  62. memset(sum,,sizeof sum);
  63. memset(col,,sizeof col);
  64. double ans=;
  65. for(int i=;i<cnt;i++)
  66. {
  67. int l=lower_bound(x+,x++k,s[i].l)-x;
  68. int r=lower_bound(x+,x++k,s[i].r)-x-;
  69. Update(l,r,s[i].s,,k,);
  70. ans+=sum[]*(s[i+].h-s[i].h);
  71. }
  72. printf("Test case #%d\nTotal explored area: %.2f\n\n",o++,ans);
  73. }
  74. return ;
  75. }
 

HDU 1542 Atlantis(线段树面积并)的更多相关文章

  1. POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并

    题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...

  2. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  3. hdu 1542 Atlantis(线段树,扫描线)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. hdu 1542 Atlantis (线段树扫描线)

    大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...

  5. HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  6. HDU 1542 Atlantis(矩形面积并)

    HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...

  7. hdu 1542 Atlantis(段树&amp;扫描线&amp;面积和)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. HDU 1542 Atlantics 线段树+离散化扫描

    将 x 轴上的点进行离散化,扫描线沿着 y 轴向上扫描 每次添加一条边不断找到当前状态有效边的长度 , 根据这个长度和下一条边形成的高度差得到一块合法的矩形的面积 #include<iostre ...

  9. Atlantis HDU - 1542 (线段树扫描线)

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

随机推荐

  1. Spring和SpringMVC的常用注解

    Spring的部分: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component-scan base-package=" ...

  2. 机器学习进阶-图像金字塔与轮廓检测-图像金字塔-(**高斯金字塔) 1.cv2.pyrDown(对图片做向下采样) 2.cv2.pyrUp(对图片做向上采样)

    1.cv2.pyrDown(src)  对图片做向下采样操作,通常也可以做模糊化处理 参数说明:src表示输入的图片 2.cv2.pyrUp(src) 对图片做向上采样操作 参数说明:src表示输入的 ...

  3. 工作记录 rfcn网络结构 caffe time测速和实际运行中速度不相等。

    现象: 用caffe time测试网络结构,前向传播是 8 ms左右, 实际集成后运行的时候,forward耗时大概4-5ms. 输入大小是一致的. 于是开始查这个问题. 最后定位到,差别在propo ...

  4. python实现排序算法二:归并排序

    ##归并排序 ##基本思想:对于两个排好序的数组A和B,逐一比较A和B的元素,将较小值放入数组C中,当A或者B数组元素查询完后,将A或者B剩余的元素直接添加到C数组中,此时C数组即为有序数组,这就是归 ...

  5. [PC]PHPCMS v9.5.6整合UEditer1.4.2

    ----------------------------------------------------------------------------------------------- 首先去U ...

  6. kickstart自动安装部署RHEL7

    Kickstart是一种无人值守的安装方式.它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个 名为ks.cfg的文件.如果在安装过程中(不只局限于生成Kickstart安装文 ...

  7. Bug : Cannot evaluate ...toString()

  8. sp_executesql 或者 EXECUTE 执行动态sql的权限问题

    当 sp_executesql 或 EXECUTE 语句执行字符串时,字符串将作为它的自包含批处理执行.SQL Server 会将字符串中的一个或多个 Transact-SQL 语句编译为独立于批处理 ...

  9. 使用jQuery+huandlebars遍历展示对象中的数组

    兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) & ...

  10. MAC下Xcode配置opencv(2017.3.29最新实践,亲测可行)(转)

    本文原创,未经同意,谢绝转载!(转载请告知本人并且经过本人同意--By Pacific-hong) 本人小硕一枚,因为专业方向图像相关,所以用到opencv,然后网上MAC下Xcode配置opencv ...