Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7815    Accepted Submission(s): 3420

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
  1. 2
  2. 10 10 20 20
  3. 15 15 25 25.5
  4. 0
 
Sample Output
  1. Test case #1
  2. Total explored area: 180.00
求面积并:
推荐博客:http://www.cnblogs.com/ka200812/archive/2011/11/13/2247064.html
我的代码:
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. using namespace std ;
  5.  
  6. double y[300] ;
  7.  
  8. struct Line{
  9. double x , y_up , y_down ;
  10. int mark ;
  11. }line[300] ; //開始开到110,WA另外三次。!
  12.  
  13. 后来看discuss改后就A了!
  14.  
  15. struct Node{
  16. double x ,y_up,y_down ;
  17. int cover ;
  18. bool isLeaf ;
  19. }st[400100];
  20.  
  21. bool cmp(const Line &a , const Line &b)
  22. {
  23. return a.x<b.x ;
  24. }
  25.  
  26. void build(int l ,int r , int pos)
  27. {
  28. st[pos].cover = 0 ;
  29. st[pos].y_down = y[l] ;
  30. st[pos].y_up = y[r] ;
  31. st[pos].x = -1 ;
  32. st[pos].isLeaf = false ;
  33. if(l+1 == r)
  34. {
  35. st[pos].isLeaf = true ;
  36. return ;
  37. }
  38. int mid = (l+r)>>1 ;
  39. build(l,mid,pos<<1);
  40. build(mid,r,pos<<1|1) ;
  41. }
  42.  
  43. double insert(double x , double y_up , double y_down , int mark , int pos)
  44. {
  45. if(st[pos].y_down>=y_up || st[pos].y_up<=y_down)
  46. {
  47. return 0 ;
  48. }
  49. if(st[pos].isLeaf)
  50. {
  51. if(st[pos].cover>0)
  52. {
  53. double temp = st[pos].x ;
  54. double area = (x-temp)*(st[pos].y_up-st[pos].y_down) ;
  55. st[pos].x = x ;
  56. st[pos].cover += mark ;
  57. return area ;
  58. }
  59. else
  60. {
  61. st[pos].x = x ;
  62. st[pos].cover += mark ;
  63. return 0 ;
  64. }
  65. }
  66. return insert(x,y_up,y_down,mark,pos<<1)+insert(x,y_up,y_down,mark,pos<<1|1) ;
  67. }
  68.  
  69. int main()
  70. {
  71. int n , c = 1;
  72. while(~scanf("%d",&n) && n)
  73. {
  74. int index = 0 ;
  75. for(int i = 0 ; i < n ; ++i)
  76. {
  77. double x1,y1,x2,y2 ;
  78. scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2) ;
  79. line[index].x = x1 ;
  80. line[index].y_down = y1 ;
  81. line[index].y_up = y2 ;
  82. y[index] = y1 ;
  83. line[index++].mark = 1 ;
  84.  
  85. line[index].x = x2 ;
  86. line[index].y_down = y1 ;
  87. line[index].y_up = y2 ;
  88. y[index] = y2 ;
  89. line[index++].mark = -1 ;
  90. }
  91. sort(y,y+index) ;
  92. sort(line,line+index,cmp) ;
  93. build(0,index-1,1) ;
  94. double area = 0.0 ;
  95. for(int i = 0 ; i < index ; ++i)
  96. {
  97. area += insert(line[i].x,line[i].y_up,line[i].y_down,line[i].mark,1) ;
  98. }
  99. printf("Test case #%d\n",c++) ;
  100. printf("Total explored area: %.2lf\n\n",area) ;
  101. }
  102. return 0 ;
  103. }

而共勉之王

hdu 1542 Atlantis 段树区,并寻求,,,尼玛真坑人数据,不要打开一小阵!的更多相关文章

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

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

  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/Ot ...

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

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

  5. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

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

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

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

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

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

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

  9. (HDU 1542) Atlantis 矩形面积并——扫描线

    n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...

随机推荐

  1. [Windwos Phone 8]多个按钮的共用事件

    原文:[Windwos Phone 8]多个按钮的共用事件 前言 ------------------------------------------------------------------- ...

  2. Java Metrics

    Java Metrics Java Metrics是一个功能比較强大的java统计库,它的输出组件也非常强大,帮我们做好了: 输出到Ganglia 输出到控制台 输出到JMX 输出Json 具体见:d ...

  3. testlink于smarty配置和使用

    于testlink于,采用smarty首先配置. 一般在过程化的编程中.创建一个smarty.inc.php的文件来配置Smarty的信息,其它文件引入就可以,目的是为了不改动smarty.class ...

  4. 怎么确定你的CPU是否支持64位虚拟化

    http://www.grc.com/securable.htm 第一个64位表示你的电脑最多支持多少位的系统,32或者64. 第二个表示你的硬件是否支持DEP?Yes,支持.No,不支持.OFF,表 ...

  5. ASP.NET 运行

    ASP.NET 运行 对于ASP.NET开发,排在前五的话题离不开请求生命周期.像什么Cache.身份认证.Role管理.Routing映射,微软到底在请求过程中干了哪些隐秘的事,现在是时候揭晓了.抛 ...

  6. 返璞归真 asp.net mvc (8) - asp.net mvc 3.0 新特性之 Model

    原文:返璞归真 asp.net mvc (8) - asp.net mvc 3.0 新特性之 Model [索引页][源码下载] 返璞归真 asp.net mvc (8) - asp.net mvc ...

  7. Windows PowerShell 简介

    Powershell 是运行在windows机器上实现系统和应用程序管理自动化的命令行脚本环境.微软之所以将Powershell 定位为Power,并不是夸大其词,因为它完全支持对象.其可读性,易用性 ...

  8. 开源Math.NET基础数学类库使用(12)C#随机数扩展方法

    原文:[原创]开源Math.NET基础数学类库使用(12)C#随机数扩展方法                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...

  9. 数据库开发——参照完整性——在外键中使用Delete on cascade选项

    原文:数据库开发--参照完整性--在外键中使用Delete on cascade选项 原文: http://www.mssqltips.com/sqlservertip/2743/using-dele ...

  10. HTML高级标签(2)————窗体分帧(1)————分帧演示

    我们能够简单的编写一个多帧的窗体,而且能够随意的划分窗体区域. <frameset rows="*,*,*"> <frameset cols="*,*& ...