题目:

Atlantis
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23758   Accepted: 8834

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 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

Source

 
  思路:
    矩形面积并,复习下。
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. #define MP make_pair
  10. #define PB push_back
  11. typedef long long LL;
  12. typedef pair<int,int> PII;
  13. const double eps=1e-;
  14. const double pi=acos(-1.0);
  15. const int K=3e2+;
  16. const int mod=1e9+;
  17.  
  18. struct node
  19. {
  20. int f;
  21. double l,r,y;
  22. bool operator < (const node &ta)const
  23. {
  24. return y<ta.y;
  25. }
  26. }seg[K*];
  27. int cover[K*];
  28. double sum[K*],hs[K*];
  29. void push_up(int o,int l,int r)
  30. {
  31. if(cover[o]) sum[o]=hs[r+]-hs[l];
  32. else if(l==r) sum[o]=;
  33. else sum[o]=sum[o<<]+sum[o<<|];
  34. }
  35. void update(int o,int l,int r,int nl,int nr,int f)
  36. {
  37. if(l==nl&&r==nr)
  38. cover[o]+=f,push_up(o,l,r);
  39. else
  40. {
  41. int mid=l+r>>;
  42. if(nr<=mid) update(o<<,l,mid,nl,nr,f);
  43. else if(nl>mid) update(o<<|,mid+,r,nl,nr,f);
  44. else update(o<<,l,mid,nl,mid,f),update(o<<|,mid+,r,mid+,nr,f);
  45. push_up(o,l,r);
  46. }
  47. }
  48. int main(void)
  49. {
  50. int n,cs=;
  51. while(scanf("%d",&n)&&n)
  52. {
  53. int cnt=;
  54. double ans=;
  55. memset(cover,,sizeof cover);
  56. memset(sum,,sizeof sum);
  57. for(int i=;i<=n;i++)
  58. {
  59. double lx,ly,rx,ry;
  60. scanf("%lf%lf%lf%lf",&lx,&ly,&rx,&ry);
  61. seg[cnt+].l=seg[cnt+].l=lx;
  62. seg[cnt+].r=seg[cnt+].r=rx;
  63. seg[cnt+].y=ry,seg[cnt+].y=ly;
  64. seg[cnt+].f=,seg[cnt+].f=-;
  65. hs[cnt+]=lx,hs[cnt+]=rx;
  66. cnt+=;
  67. }
  68. sort(seg+,seg++n*);
  69. sort(hs+,hs++*n);
  70. int sz=unique(hs+,hs++n*)-hs;
  71. for(int i=;i<*n;i++)
  72. {
  73. int l=lower_bound(hs+,hs+sz,seg[i].l)-hs;
  74. int r=lower_bound(hs+,hs+sz,seg[i].r)-hs;
  75. update(,,sz,l,r-,seg[i].f);
  76. ans+=sum[]*(seg[i+].y-seg[i].y);
  77. }
  78. printf("Test case #%d\nTotal explored area: %.2f\n\n",cs++,ans);
  79. }
  80. return ;
  81. }

poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并的更多相关文章

  1. [POJ1151]Atlantis

    [POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...

  2. Three.js 火焰效果实现艾尔登法环动态logo 🔥

    声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 <艾尔登法环>是最近比较火的一款游戏,观察可以发现它的 Log ...

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

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

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

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

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

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

  6. 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)

    [题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...

  7. 10.我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?

    我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形. 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 是不是发现看不懂,哈哈:编程题就是这样,一定要归纳,手写过程: n ...

  8. poj-1151矩形面积并-线段树

    title: poj-1151矩形面积并-线段树 date: 2018-10-30 22:35:11 tags: acm 刷题 categoties: ACM-线段树 概述 线段树问题里的另一个问题, ...

  9. hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]

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

随机推荐

  1. Python 中文乱码

    1.首行添加 # -*- coding:gb2312 -*- # -*- coding:utf-8 -*- 2.PyCharm设置 在File->setting->File Encodin ...

  2. ch6-定制数据对象(打包代码和数据)

    为了看出数据属于哪个选手,教练向各个选手的数据文件中添加了标识数据:选手全名,出生日期,计时数据. 例如:sarah文件的数据更新为: Sarah Sweeney,2002-6-17,2:58,2.5 ...

  3. Python 使用正则表达式匹配电话号码

    一个电话号码,如果区号为3位,那么区号后面的数字为8位:如果区号为4位,那么区号后面的数字为7位 In [1]: import re In [2]: number = "020-232432 ...

  4. getViewTreeObserver

    在项目中或多或少会遇一一些异步的操作,比如自定中不能马上获取到高度用测试可以得到.. final View headerView = View.inflate(this, R.layout.layou ...

  5. 【Linux系列】find命令使用

    Linux下find命令在目录结构中搜素文件,病执行制定的操作. 一.命令格式 find pathname -options[-print -exec -ok] 二.命令功能 用于在文件树种查找文件, ...

  6. JavaWeb温习之Cookie对象

    1. 会话的概念 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话.有状态会话:一个同学来过教室,下次再来教室,我们会知道这个同学曾 ...

  7. log4j和commons- logging(好文整理转载)

    一 :为什么同时使用commons-logging和Log4j?为什么不仅使用其中之一? Commons-loggin的目的是为 “所有的Java日志实现”提供一个统一的接口,它自身的日志功能平常弱( ...

  8. docker swarm+register-web+shipyard搭建

    1.swarm安装 swarm安装有很多种服务注册的方式,token.etcd.zookeeper,本文主要以swarm默认的token方式进行安装.因为最新的docker已经集成了swarm,所以从 ...

  9. JS拖拽事件

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. JS生成GUID方法

    function GUID() { this.date = new Date(); /* 判断是否初始化过,如果初始化过以下代码,则以下代码将不再执行,实际中只执行一次 */ if (typeof t ...