题目:http://poj.org/problem?id=1151
Atlantis
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20276   Accepted: 7657

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

2
10 10 20 20
15 15 25 25.5
0

Sample Output

Test case #1
Total explored area: 180.00 

Source

Mid-Central European Regional Contest 2000

题解:

矩形切割

这道题和 poj2528 类似,只不过变成了矩形。

具体可以看上一篇博客,关于线段切割的概括。

然后就多加两个判断就好了。

程序很好写,时间也不错(比线段树高到不知道哪里去了,我和它谈笑风生?)

注意:相邻两个数据间要输出换行。PE了一发。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define MAXN 110
 4 int n;
 5 double XX1[MAXN],YY1[MAXN],XX2[MAXN],YY2[MAXN],ans[MAXN];
 6 void Cover(double X1,double Y1,double X2,double Y2,int k,int k1)
 7 {
 8     while(k<=n&&(X1>=XX2[k]||X2<=XX1[k]||Y1>=YY2[k]||Y2<=YY1[k]))k++;
 9     if(k>=n+1){ans[k1]+=(X2-X1)*(Y2-Y1);return;}
10     if(X1<XX1[k])
11     {
12         Cover(X1,Y1,XX1[k],Y2,k+1,k1);
13         X1=XX1[k];
14     }
15     if(X2>XX2[k])
16     {
17         Cover(XX2[k],Y1,X2,Y2,k+1,k1);
18         X2=XX2[k];
19     }
20     if(Y1<YY1[k])
21     {
22         Cover(X1,Y1,X2,YY1[k],k+1,k1);
23         Y1=YY1[k];
24     }
25     if(Y2>YY2[k])
26     {
27         Cover(X1,YY2[k],X2,Y2,k+1,k1);
28         Y2=YY2[k];
29     }
30 }
31 int main()
32 {
33     int i,case1=0;
34     double sum;
35     while(1)
36     {
37         scanf("%d",&n);if(n==0)break;
38         for(i=1;i<=n;i++){scanf("%lf %lf %lf %lf",&XX1[i],&YY1[i],&XX2[i],&YY2[i]);}
39         memset(ans,0,sizeof(ans));
40         for(i=n;i>=1;i--)Cover(XX1[i],YY1[i],XX2[i],YY2[i],i+1,i);
41         sum=0.0;
42         for(i=1;i<=n;i++)sum+=ans[i];
43         printf("Test case #%d\n",++case1);
44         printf("Total explored area: %.2lf\n\n",sum);
45     }
46     fclose(stdin);
47     fclose(stdout);
48     return 0;
49 }

转载于:https://www.cnblogs.com/Var123/p/5367351.html

Poj 1151-Atlantis 矩形切割相关推荐

  1. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

  2. poj 1151 Atlantis

    类型:离散化 题目:http://poj.org/problem?id=1151 来源:Mid-Central European Regional Contest 2000 思路[一]: (1)使用m ...

  3. POJ 1151 Atlantis 线段树+扫描线

    解题思路: 先将y轴进行离散化.n个矩形的2n个横边纵坐标共构成最多2n-1个区间的边界,对这些区间编号,建立起线段树. x轴记录左边和右边,左边时是矩形面积增加,覆盖层数增加边,右边是形面积减少,覆 ...

  4. 扫描线三巨头 hdu1928hdu 1255 hdu 1542 [POJ 1151]

    学习链接:http://blog.csdn.net/lwt36/article/details/48908031 学习扫描线主要学习的是一种扫描的思想,后期可以求解很多问题. 扫描线求矩形周长并 hd ...

  5. POJ1151(矩形切割入门题)

    题目:Atlantis 我的上一篇文章已经讲明了线段切割的思想,矩形切割就是把线段切割从一维推到二维就行了,思想都一样. #include <stdio.h> #include <s ...

  6. POJ3277(矩形切割)

    题目:City Horizon 题意:实际上就是求面积的并.因为是面积和的问题,所以越宽越高的肯定应该放在后面,低的先被覆盖. 以后在做矩形切割题目的时候最好先排序,那样不容易超时. #include ...

  7. 算法学习之——矩形切割思想

    算法学习之--矩形切割思想                                                      MPS [定义 Define]   对于求解若干个矩形的面积的交集 ...

  8. 【数学】C107_LQ_报纸页数 平方怪圈 猴子分香蕉 方格计数 矩形切割(归纳法 | 打印归纳)

    一.报纸页数 X星球日报和我们地球的城市早报是一样的,都是一些单独的纸张叠在一起而已.每张纸印有4版. 比如,某张报纸包含的4页是:5,6,11,12,可以确定它应该是最上边的第2张报纸.我们在太空中 ...

  9. usaco Section 3.1 Shaping Regions -- 矩形切割

    听说这道题用矩形切割做,于是学习了2004薛矛的oi论文. 我的做法是:弄一个白纸集合,开始里面只有一张白纸(0,0) (A,B).然后把输入的N个矩形倒序地,每一个都与白纸集合中的所有白纸依次切割. ...

最新文章

  1. iis上实现虚拟目录
  2. (C++)201709-1 打酱油
  3. Linux内核开发工作方向
  4. 归并排序(python实现)
  5. 大型网站系统架构实践(五)深入探讨web应用高可用方案
  6. 解答网友提问:如何构建动态表达式实现高级查询服务
  7. EF6源码学习-准备篇
  8. LeetCode 66. Plus One
  9. php bloginfo templatedirectory,PHP变量不显示使用bloginfo('template_directory')的图像
  10. 数字ab写成c语言表达式,《c语言程序设计》复习题.pdf
  11. python面向对象训练
  12. cesium 获取当前经纬度和视角还有当前level层级
  13. iText和flying saucer结合生成pdf--显示分页页码
  14. 免费在线打字练习网站
  15. Scratch互动编程手柄兼容mblock网易卡搭慧编程猫Mind+ 编程键盘手柄20210223
  16. 自考启示,关于不紧急重要到紧急重要的改变
  17. c语言解三色旗问题加注释,三色旗问题(Three
  18. 计算机仿真塞曼效应实验报告,塞曼效应实验报告[完整版].doc
  19. async和await的用法
  20. 运维监控工具之商用软件篇

热门文章

  1. jmeter基本测试步骤
  2. 安全之美(英文影印版)
  3. java如何监听以太坊交易
  4. QA32中的出口 “STATTEXT”
  5. 总结ISO各层协议都有哪些
  6. Codejock的使用--皮肤
  7. Linq To select
  8. 总结MYSQL的优化
  9. Android:Handler的消息机制
  10. DApp基础设施设计:借助Kubernetes、Docker和Parity实现可靠的以太坊事件跟踪