hdu1542 Atlantis (线段树+矩阵面积并+离散化)
InputThe 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.OutputFor 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 思路:
扫描线+矩阵面积并,被离散化难到了,之前一直没想到离散化要弄成一个左开右闭的区间 实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int M = 1e5+;
struct seg{
double l,r,h;
int s;
seg(){}
seg(double a,double b,double c,int d):l(a),r(b),h(c),s(d){}
bool operator < (const seg &cmp) const {
return h < cmp.h;
}
}t[M];
double sum[M<<],x[M<<];
int cnt[M<<];
void pushup(int l,int r,int rt){
if(cnt[rt]) sum[rt] = x[r+] - x[l];
else if(l == r) sum[rt] = ;
else sum[rt] = sum[rt<<] + sum[rt<<|];
} void update(int L,int R,int c,int l,int r,int rt){
if(L <= l&&R >= r){
cnt[rt] += c;
pushup(l,r,rt);
return ;
}
mid;
if(L <= m) update(L,R,c,lson);
if(R > m) update(L,R,c,rson);
pushup(l,r,rt);
} int bin(double key,int n,double x[]){
int l = ;int r = n-;
while(l <= r){
mid;
if(x[m] == key) return m;
else if(x[m] < key) l = m+;
else r = m-;
}
return -;
}
int main()
{
int n,cas = ;
double a,b,c,d;
while(~scanf("%d",&n)&&n){
int m = ;
while(n--){
cin>>a>>b>>c>>d;
x[m] = a;
t[m++] = seg(a,c,b,);
x[m] = c;
t[m++] = seg(a,c,d,-);
}
sort(x,x+m);
sort(t,t+m);
int nn = ;
for(int i = ;i < m;i++){
if(x[i]!=x[i-]) x[nn++] = x[i];
}
//for(int i = 0;i < nn;i ++)
// cout<<x[i]<<" ";
//cout<<endl;
double ret = ;
for(int i = ;i < m-;i ++){
int l = bin(t[i].l,nn,x);
int r = bin(t[i].r,nn,x)-;
//cout<<t[i].l<<" "<<t[i].r<<endl;
//cout<<"l: "<<l<<" r: "<<r<<endl;
if(l <= r) update(l,r,t[i].s,,nn-,);
//cout<<sum[1]<<endl;
ret += sum[] * (t[i+].h - t[i].h);
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n",cas++ , ret);
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
}
return ;
}
hdu1542 Atlantis (线段树+矩阵面积并+离散化)的更多相关文章
- hdu1542 Atlantis 线段树--扫描线求面积并
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- hdu1542(线段树——矩形面积并)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 分析:离散化+扫描线+线段树 #pragma comment(linker,"/STA ...
- hdu 1542 线段树扫描(面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- 2017ICPC南宁赛区网络赛 Overlapping Rectangles(重叠矩阵面积和=离散化模板)
There are nnn rectangles on the plane. The problem is to find the area of the union of these rectang ...
- Wannafly Winter Camp 2019.Day 8 div1 E.Souls-like Game(线段树 矩阵快速幂)
题目链接 \(998244353\)写成\(99824435\)然后调这个线段树模板1.5h= = 以后要注意常量啊啊啊 \(Description\) 每个位置有一个\(3\times3\)的矩阵, ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- HDU - 1542 Atlantis(线段树求面积并)
https://cn.vjudge.net/problem/HDU-1542 题意 求矩形的面积并 分析 点为浮点数,需要离散化处理. 给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1).(x ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
随机推荐
- oracle存储过程 关于update的动态SQL-工作心得
本随笔文章,由个人博客(鸟不拉屎)转移至博客园 发布时间: 2018 年 12 月 20 日 原地址:https://niaobulashi.com/archives/oracle-procedure ...
- SQL Operations Studio的安装和使用
之前管理和访问SQL SERVER使用的自然是SSMS,功能确实很强大的一个数据库图形化管理软件,但是SSMS有个问题就是体积超级大,启动速度也就比较慢.今天我正好要学习一些T-SQL的内容,在微软的 ...
- Netty源码分析第7章(编码器和写数据)---->第1节: writeAndFlush的事件传播
Netty源码分析第七章: 编码器和写数据 概述: 上一小章我们介绍了解码器, 这一章我们介绍编码器 其实编码器和解码器比较类似, 编码器也是一个handler, 并且属于outbounfHandle ...
- 安装GNU Radio及相关常用SDR软件的最简单方法
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- smash:一个类unix内核
前言 每一个蹩脚的C++程序员都有一颗做操作系统内核的心.我从大学毕业开始就对操作系统内核感兴趣,将其看作是术之尽头,可惜那时候一直在无忧无虑的忙着玩网游,也就搁置了.随着时间的推移,逐渐就将其淡忘了 ...
- MySQL基础练习(三)
经过之前两次的学习,这次用MySQL进行略微复杂的操作练习 各部门工资最高的员工 首先创建表employee和表department.如下 我们需要查询每个部门工资最高的员工 select a.Nam ...
- 机器装多个版本php,并安装redis插件报错【已解决】
机器原版本php5.5.3 适应新的框架安装了7.1.12 期间遇到的小问题就是安装 redis插件的时候,总报错,报错如下: Starting php-fpm [02-Jan-2019 10:15: ...
- Spring MVC controller的方法返回值
ModeAndView 可以在构造时确定需要跳转的页面也可以通过setViewName方法来确定需要跳转的页面 String 指定返回页面的视图名称,页面跳转,如果加了@ResponseBody注解, ...
- 20172325 2016-2017-2 《Java程序设计》第四周学习总结
20172325 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 1.对类.对象.声明变量的定义和属性有了进一步的了解 2.学会如何编写一个类并运用到需要的程 ...
- php----函数大全
字符串函数 数组函数 数学函数