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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define lz 2*u,l,mid
#define rz 2*u+1,mid+1,r
const int maxn=;
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<S.y;
}
}line[maxn]; int find(double tmp, int n)
{
int l=, r=n, mid;
while(l<=r)
{
mid=(l+r)>>;
if(X[mid]==tmp) return mid;
else if(X[mid]<tmp) l=mid+;
else r=mid-;
}
} void push_up(int u, int l, int r)
{
if(flag[u]) sum[u]=X[r+]-X[l];
else if(l==r) sum[u]=;
else sum[u]=sum[*u]+sum[*u+];
} void Update(int u, int l, int r, int tl, int tr, int c)
{
if(tl<=l&&r<=tr)
{
flag[u]+=c;
push_up(u,l,r);
return ;
}
int mid=(l+r)>>;
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+,tr,c);
}
push_up(u,l,r);
} int main()
{
int n,tcase=;
while(cin >> n,n)
{
int num=;
memset(flag,,sizeof(flag));
memset(sum,,sizeof(sum));
for(int i=; i<n; i++)
{
double x1,x2,y1,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[++num]=Node(x1,x2,y1,);
X[num]=x1;
line[++num]=Node(x1,x2,y2,-);
X[num]=x2;
}
sort(X+,X+num+);
sort(line+,line+num+);
int k=*n;
double ans=;
for(int i=; i<num; i++)
{
int l=find(line[i].lx,k);
int r=find(line[i].rx,k)-1;
Update(,,k,l,r,line[i].s);
ans+=sum[]*(line[i+].y-line[i].y);
}
printf("Test case #%d\n",++tcase);
printf("Total explored area: %.2lf\n\n",ans);
}
return ;
}
 

矩阵重叠面积计算 线段树hdu1542的更多相关文章

  1. hdu1542矩阵的并 线段树+扫描线

    求矩阵的并,也就是要求所有的面积.那可以吧总的图形按照矩阵来切割.使其为一块一块. 输入的时候用坐标表示,这里扫描线从下到上扫描.初始时让下面的边为1,上面的为-1: 用一条先从下面开始想上扫描.遇到 ...

  2. Codeforces 719E [斐波那契区间操作][矩阵快速幂][线段树区间更新]

    /* 题意:给定一个长度为n的序列a. 两种操作: 1.给定区间l r 加上某个数x. 2.查询区间l r sigma(fib(ai)) fib代表斐波那契数列. 思路: 1.矩阵操作,由矩阵快速幂求 ...

  3. Codeforces Round #373 (Div. 2) E. Sasha and Array 矩阵快速幂+线段树

    E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  4. E. Sasha and Array 矩阵快速幂 + 线段树

    E. Sasha and Array 这个题目没有特别难,需要自己仔细想想,一开始我想了一个方法,不对,而且还很复杂,然后lj提示了我一下说矩阵乘,然后再仔细想想就知道怎么写了. 这个就是直接把矩阵放 ...

  5. [NOI P模拟赛] 传统艺能(子序列自动机、矩阵乘法,线段树)

    (2:00)OID:"完了,蓝屏了!"(代码全消失) 众人欢呼 OID:开机,"原题测试--" (30min later)OID 开始传统艺能: " ...

  6. hdu1255 矩阵的交 线段树+扫描线

    /* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[ ...

  7. HDU 6155 Subsequence Count(矩阵乘法+线段树+基础DP)

    题意 给定一个长度为 \(n\) 的 \(01\) 串,完成 \(m\) 种操作--操作分两种翻转 \([l,r]\) 区间中的元素.求区间 \([l,r]\) 有多少个不同的子序列. \(1 \le ...

  8. Subsequence Count 2017ccpc网络赛 1006 dp+线段树维护矩阵

    Problem Description Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries ...

  9. HDU 6155 Subsequence Count 线段树维护矩阵

    Subsequence Count Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Oth ...

随机推荐

  1. java内存模型(JMM)和happens-before

    目录 重排序 Happens-Before 安全发布 初始化安全性 java内存模型(JMM)和happens-before 我们知道java程序是运行在JVM中的,而JVM就是构建在内存上的虚拟机, ...

  2. vue2.x学习笔记(二十八)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12682573.html. 生产环境部署 以下大多数内容在你使用vue cli的时候都是默认开启的,仅跟你自定义的构 ...

  3. 第三方库 正则表达式re模块

    正则表通常被用来检索.替换那些符合某个模式(规则)的文本. 正则表达式通常缩写成“regex”,单数有regexp.regex,复数有regexps.regexes.regexen. 正则表达式是对字 ...

  4. mac OS 卸载node.js及npm

    通过homebrew安装的 输入卸载命令 brew uninstall node 通过官网下载pkg安装包的 输入卸载命令 sudo rm -rf /usr/local/{bin/{node,npm} ...

  5. linux-网络管理(常用命令)

    网络查看 ifconfig : 查看与临时配置网络 ifdown 网卡设备名 : 关闭网卡 ifup 网卡设备名 : 启用网卡 netstat 网络状态查询 -t 列出TCP协议端口 -u 列出UDP ...

  6. 在TX2上多线程读取视频帧进行caffe推理

    参考文章:Multi-threaded Camera Caffe Inferencing TX2之多线程读取视频及深度学习推理 背景 一般在TX2上部署深度学习模型时,都是读取摄像头视频或者传入视频文 ...

  7. python(类继承)

    一.继承 1.单继承 一个对象使用另一个对象的属性和方法,被继承的类也称父类 (1)父类与子类的方法不一样 class Four(): def sub(self,x,y): return x + y ...

  8. 题目分享T

    题意:蛐蛐国里现在共有n只蚯蚓(n为正整数).每只蚯蚓拥有长度,我们设第i只蚯蚓的长度为a_i(i=1,2,...,n),并保证所有的长度都是非负整数(即:可 能存在长度为0的蚯蚓).每一秒,神刀手会 ...

  9. Kubernetes实战总结

    >>> 目录 <<< 一.概述二.核心组件三.基本概念四.系统架构五.镜像制作六.服务编排七.持续部署八.故障排查 >>> 正文 << ...

  10. SpringBoot:整合SpringSecurity

    目录 SpringSecurity(安全) 搭建环境 使用 用户认证和授权 注销及权限控制 记住我及登录页面定制 SpringBoot 整合 SpringSecurity: 用户认证和授权.注销及权限 ...