Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5932    Accepted Submission(s): 2599

Problem Description
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
 
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. using namespace std;
  5. typedef struct node
  6. {
  7. double x,y1,y2;
  8. int flag;
  9. } node;
  10. typedef struct tree
  11. {
  12. double y1,y2,x;
  13. double cover;
  14. bool flag;
  15. } treee;
  16. node n[];
  17. treee tree[];
  18. double q[];
  19. bool cmp(node a,node b)
  20. {
  21. return a.x<b.x;
  22. }
  23. void build(int l,int r,int t)
  24. {
  25. tree[t].cover=;
  26. tree[t].flag=false;
  27. tree[t].x=-;
  28. tree[t].y1=q[l];
  29. tree[t].y2=q[r];
  30. if(l+==r)
  31. {
  32. tree[t].flag=true;
  33. return ;
  34. }
  35. int m=(l+r)>>;
  36. build(l,m,t<<);
  37. build(m,r,t<<|);
  38. }
  39. double insert(double x,double y1,double y2,int t,int cover)
  40. {
  41. if(tree[t].y1>=y2||tree[t].y2<=y1)
  42. {
  43. return ;
  44. }
  45. if(tree[t].flag)
  46. {
  47. if(tree[t].cover>)
  48. {
  49. double sum=,x1=tree[t].x;
  50. sum=(x-x1)*(tree[t].y2-tree[t].y1);
  51. tree[t].cover+=cover;
  52. tree[t].x=x;
  53. return sum;
  54. }
  55. else
  56. {
  57. tree[t].cover+=cover;
  58. tree[t].x=x;
  59. return ;
  60. }
  61. }
  62. return insert(x,y1,y2,t<<,cover)+insert(x,y1,y2,t<<|,cover);
  63. }
  64. int main()
  65. {
  66. double x,y,xx,yy;
  67. int m,t,i,ww=;
  68. while(~scanf("%d",&m)&&m)
  69. {
  70. t=;
  71. for(i=; i<m; i++)
  72. {
  73. scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy);
  74. q[t]=y;
  75. n[t].flag=;
  76. n[t].x=x;
  77. n[t].y1=y;
  78. n[t++].y2=yy;
  79. q[t]=yy;
  80. n[t].flag=-;
  81. n[t].x=xx;
  82. n[t].y1=y;
  83. n[t++].y2=yy;
  84. }
  85. sort(n+,n+t,cmp);
  86. sort(q+,q+t);
  87. build(,t-,);
  88. double sum=;
  89. for(i=; i<t; i++)
  90. {
  91. sum+=insert(n[i].x,n[i].y1,n[i].y2,,n[i].flag);
  92. }
  93. cout<<"Test case #"<<ww++<<endl;
  94. cout<<"Total explored area: ";
  95. printf("%.2lf\n\n",sum);
  96. }
  97. }
 
 
 

hdu 1542 线段树 求矩形并的更多相关文章

  1. HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)

    链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...

  2. hdu 1542 线段树扫描(面积)

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

  3. UVA 11983 Weird Advertisement --线段树求矩形问题

    题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...

  4. 【hdu1542】线段树求矩形面积并

    分割线内容转载自http://hzwer.com/879.html ------------------------------------------------------------------ ...

  5. POJ 1151 Atlantis 线段树求矩形面积并 方法详解

    第一次做线段树扫描法的题,网搜各种讲解,发现大多数都讲得太过简洁,不是太容易理解.所以自己打算写一个详细的.看完必会o(∩_∩)o 顾名思义,扫描法就是用一根想象中的线扫过所有矩形,在写代码的过程中, ...

  6. hdu 1394 (线段树求逆序数)

    <题目链接> 题意描述: 给你一个有0--n-1数字组成的序列,然后进行这样的操作,每次将最前面一个元素放到最后面去会得到一个序列,那么这样就形成了n个序列,那么每个序列都有一个逆序数,找 ...

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

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

  8. HDU 1828 / POJ 1177 Picture --线段树求矩形周长并

    题意:给n个矩形,求矩形周长并 解法:跟求矩形面积并差不多,不过线段树节点记录的为: len: 此区间线段长度 cover: 此区间是否被整个覆盖 lmark,rmark: 此区间左右端点是否被覆盖 ...

  9. UVA 11983 Weird Advertisement(线段树求矩形并的面积)

    UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...

随机推荐

  1. Porita详解----Items

    Items(项目) 一个item是指从目标网站上爬取的一条单独的数据.例如从京东网站上爬取的一款小米6手机的信息.大家应该对 item (项目)和 item definition(项目定义)做一个区分 ...

  2. vue学习日志(一):vue的优势

    vue的中文官方文档里面有对比其他框架的具体介绍,这里只是做一个概括总结: 1,在 Vue 应用中,组件的依赖是在渲染过程中自动追踪的,所以系统能精确知晓哪个组件确实需要被重渲染.你可以理解为每一个组 ...

  3. js实现换肤效果

    一,js换肤的基本原理 基本原理很简单,就是使用 JS 切换对应的 CSS 样式表文件.例如导航网站 Hao123 的右上方就有网页换肤功能.除了切换 CSS 样式表文件之外,通常的网页换肤还需要通过 ...

  4. C# xml增删查改

    C# XML XmlDocument 添加命名空间: using System.Xml; 定义公共对象: XmlDocument xmldoc ; XmlNode xmlnode ; XmlEleme ...

  5. Java web servers 间是如何实现 session 同步的

     Java web servers 间是如何实现 session 同步的 有一个多月的时间没有更新博客了,今天终于忙里偷闲,可以把近期的收获总结一下. 本文是关于Java web servers 之间 ...

  6. CAS单点登陆 SSO

    什么是单点登陆 SO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统.它包括可以将这次主要的登录映射到其他应用中用于同一个用户的登录的机制.它是目前比较流行的企业业务整合的解决方 ...

  7. java aio nio bio

    转自:http://blog.csdn.NET/liuxiao723846/article/details/45066095 Java中的IO主要源自于网络和本地文件 IO的方式通常分为几种,同步阻塞 ...

  8. 201521123051《Java程序设计》第八周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 集合与泛型综合示例 import java.util.ArrayLis ...

  9. 201521123010 《Java程序设计》第7周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 ①ArrayList代码分析 1.1 解释ArrayList的contains源代码 ...

  10. java从控制台接收一个数字

    //时间:2017/7/22//作者:江骆//功能:从控制台接收一个数import java.io.*;  //引入一个IO流的包public class helloworld1{    public ...