博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板
阅读量:5076 次
发布时间:2019-06-12

本文共 2951 字,大约阅读时间需要 9 分钟。

好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解。现在来水一水博客,写一下若干年前的题目的题解。

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

Total Submission(s): 21978    Accepted Submission(s): 8714

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
 

 

Source
 
 
题目就是求矩形面积并。扫描线。
一开始不知道扫描线是个什么东西的时候,感觉很厉害的东西,知道是什么之后,就。。。
就是区间更新的问题,因为在这里线段树维护的是线段,不是点,所以每个点代表的其实是一条线段,所以会有什么+1,-1的操作。
 
具体的看代码。
 
代码:
1 #include
2 using namespace std; 3 typedef long long ll; 4 const int maxn=2e4+10; 5 #define lson l,m,rt<<1 6 #define rson m+1,r,rt<<1|1 7 8 int cnt[maxn<<2]; 9 double sum[maxn<<2],f[maxn];10 11 void init()12 {13 memset(cnt,0,sizeof cnt);14 memset(sum,0,sizeof sum);15 }16 17 struct node{18 double h,l,r;19 int s;20 21 node(){}22 23 node(double a,double b,double c,int d):l(a),r(b),h(c),s(d){}24 25 bool operator<(const node&cmp){26 return h
>1;53 if(L<=m) update(L,R,c,lson);54 if(R> m) update(L,R,c,rson);55 pushup(rt,l,r);56 }57 58 int main()59 {60 int n,cas=1;61 while(~scanf("%d",&n)&&n){62 int h=0;63 for(int i=1;i<=n;i++){
//从下往上扫64 double a,b,c,d;65 scanf("%lf%lf%lf%lf",&a,&b,&c,&d);66 f[h]=a;67 line[h++]=node(a,c,b,1);//标记入边68 f[h]=c;69 line[h++]=node(a,c,d,-1);//标记出边70 }71 sort(f,f+h);72 sort(line,line+h);73 int d=unique(f,f+h)-f;//离散化74 init();75 double ret=0;76 for(int i=0;i

 

 

开溜。

 

转载于:https://www.cnblogs.com/ZERO-/p/10982343.html

你可能感兴趣的文章
App右上角数字
查看>>
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)【转】
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
[ZJOI2007]棋盘制作 【最大同色矩形】
查看>>
IOS-图片操作集合
查看>>
模板统计LA 4670 Dominating Patterns
查看>>
团队项目开发客户端——登录子系统的设计
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
session如何保存在专门的StateServer服务器中
查看>>
react展示数据
查看>>