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 ...
随机推荐
- 对最近java基础学习的一次小结
开头想了3分钟,不知道起什么名字好,首先内容有点泛,但也都是基础知识. 对之前所学的java基础知识做了个小结,因为我是跟着网上找的黑马的基础视频看跟着学的,10天的课程硬生生给我看了这么久,也是佛了 ...
- Egret入门(一)--简介
关于Egret 构建2D游戏,开源. TS + JS 完成打包后可以转换成HTML5的游戏(跨平台) Egret特点 1. 优秀的设计思想 2. 高效的渲染模块 3. 完善的配套工具 4. 灵活的工作 ...
- LeetCode 刷题笔记 155. 最小栈(Min Stack)
tag: 栈(stack) 题目描述 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素 ...
- Python 夺大满贯!三大编程语言榜即将全部“失守”!
有互联网创业者说: 2019年可能会是过去十年里最差的一年 但却是未来十年里最好的一年 真的是这样吗? “每月工资1w,如何赚到200w?” 同样一个问题,问不同的人会得到不同的答案. 有一类人,开始 ...
- Python数据分析工具库-Numpy 数组支持库(一)
1 Numpy数组 在Python中有类似数组功能的数据结构,比如list,但在数据量大时,list的运行速度便不尽如意,Numpy(Numerical Python)提供了真正的数组功能,以及对数据 ...
- [shell] 一次性赋值多个变量
管道符是fork子进程,子进程的变量无法传回父进程 [root@XM-v106 ~]# echo "1 2 3" | read a b c;echo $a [root@XM-v10 ...
- 常用DB2命令
建库 db2 territory CN on 建库到指定位置 db2 create database OADB on D: using codeset GBK territory CN 列出所有数据库 ...
- “Hello World!”团队第六周第七次会议
博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.checkout&push代码 一.会议时间 2017年11月23日 ...
- JavaScript实现大整数减法
继上一篇博文写了大整数加法之后,我又模拟上篇博文的算法,自己实现了大整数减法. 大整数减法相对于加法来说,稍微复杂一点.由于要考虑一些情况: 1. 两个数相减,可能会出现结果为正.负和0三种情况: 2 ...
- 冲刺One之站立会议8 /2015-5-21
今天我们把聊天界面做了优化和改进,主要实现了聊天的功能.显示了正在进行通信的成员列表,和当前状态,是否连通和正常通信,大体完成了预期的目标. 燃尽图8