博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
矩阵重叠面积计算 线段树hdu1542
阅读量:4326 次
发布时间:2019-06-06

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

Atlantis

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

Total Submission(s): 14378    Accepted Submission(s): 5931

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
 
 
线段树的结点是左闭右闭(一般) ,  如果这段区间[L,R] R已经被填补了的话(在r-1地情况下,那么要填补缝隙所以这段就是左闭右+1闭)  因为如果单纯地X[r]-X[l]少加了多个节点之间的缝隙,但如果改成X[r+1]-X[l]最后一个又多加了。   而查询前先将r-=1两个条件就都能满足了;另外这道题是可以加懒惰标记的。。但是由于离散后范围也很小所以就不加了,。。。。
#include 
#include
#include
#include
using namespace std;#define lz 2*u,l,mid#define rz 2*u+1,mid+1,rconst int maxn=4222;double sum[maxn];int flag[maxn];double X[maxn];struct Node{ double lx, rx, y; int s; Node(){}; Node(double lx_, double rx_, double y_, int s_) { lx=lx_, rx=rx_, y=y_, s=s_; } bool operator <(const Node &S) const { return y
>1; if(X[mid]==tmp) return mid; else if(X[mid]
>1; if(tr<=mid) Update(lz,tl,tr,c); else if(tl>mid) Update(rz,tl,tr,c); else { Update(lz,tl,mid,c); Update(rz,mid+1,tr,c); } push_up(u,l,r);}int main(){ int n,tcase=0; while(cin >> n,n) { int num=0; memset(flag,0,sizeof(flag)); memset(sum,0,sizeof(sum)); for(int i=0; i

 

 

 

转载于:https://www.cnblogs.com/mfys/p/7594645.html

你可能感兴趣的文章
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>
VsVim - Shortcut Key (快捷键)
查看>>
C++练习 | 模板与泛式编程练习(1)
查看>>
HDU5447 Good Numbers
查看>>
08.CXF发布WebService(Java项目)
查看>>
java-集合框架
查看>>
RTMP
查看>>
求一个数的整数次方
查看>>
点云PCL中小细节
查看>>
铁路信号基础
查看>>
Django 学习笔记(五) --- Ajax 传输数据
查看>>
Spring boot 日志 Logback
查看>>
基于OWIN WebAPI 使用OAUTH2授权服务【授权码模式(Authorization Code)】
查看>>
[深入Maven源代码]maven绑定命令行参数到具体插件
查看>>
laravel 分页使用
查看>>
RobotFramework自动化2-自定义关键字
查看>>
centos6.4-x86-64系统更新系统自带Apache Http Server
查看>>
[置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
查看>>
BABOK - 需求分析(Requirements Analysis)概述
查看>>