博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1542 线段树 求矩形并
阅读量:6305 次
发布时间:2019-06-22

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

                                               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 
2 #include
3 #include
4 using namespace std; 5 typedef struct node 6 { 7 double x,y1,y2; 8 int flag; 9 } node;10 typedef struct tree11 {12 double y1,y2,x;13 double cover;14 bool flag;15 } treee;16 node n[400];17 treee tree[10000000];18 double q[400];19 bool cmp(node a,node b)20 {21 return a.x
>1;36 build(l,m,t<<1);37 build(m,r,t<<1|1);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 0;44 }45 if(tree[t].flag)46 {47 if(tree[t].cover>0)48 {49 double sum=0,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 else56 {57 tree[t].cover+=cover;58 tree[t].x=x;59 return 0;60 }61 }62 return insert(x,y1,y2,t<<1,cover)+insert(x,y1,y2,t<<1|1,cover);63 }64 int main()65 {66 double x,y,xx,yy;67 int m,t,i,ww=1;68 while(~scanf("%d",&m)&&m)69 {70 t=1;71 for(i=0; i
View Code

 

 
 
 

转载于:https://www.cnblogs.com/ERKE/p/3571318.html

你可能感兴趣的文章
Visual Studio 15.4发布,新增多平台支持
查看>>
有赞透明多级缓存解决方案(TMC)设计思路
查看>>
如何设计高扩展的在线网页制作平台
查看>>
Git 2.5增加了工作树、改进了三角工作流、性能等诸多方面
查看>>
Swift 5将强制执行内存独占访问
查看>>
中台之上(二):为什么业务架构存在20多年,技术人员还觉得它有点虚?
查看>>
深度揭秘腾讯云低功耗广域物联网LPWAN 技术及应用
查看>>
与Jeff Sutherland谈敏捷领导力
查看>>
More than React(四)HTML也可以静态编译?
查看>>
React Native最佳学习模版- F8 App开源了
查看>>
云服务正在吞噬世界!
查看>>
阅读Android源码的一些姿势
查看>>
Web语义化标准解读
查看>>
一份代码构建移动、桌面、Web全平台应用
查看>>
高性能 Lua 技巧(译)
查看>>
区分指针、变量名、指针所指向的内存
查看>>
异步编程的世界
查看>>
最近话题火爆的四件事你知道不?
查看>>
SpringBoot整合MyBatis
查看>>
云计算产业如何率先推行信用管理?
查看>>