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 ...
随机推荐
- 关于Netty的学习前总结
摘要 前段时间一直在学习netty因为工作忙的原因没有写一个学习的总结,今天抽个空先把总结写了吧.事先声明,本文不会详细的介绍每一个部分不过每个部分都会附上讲解详细的url.本文只是为了解释通Nett ...
- Go语言2
Go语言特点: 类型检查:编译时 运行环境:编译成机器代码直接运行 编程范式:面向接口,函数式编程,并发编程 Go并发编程 采用CSP(Communication Sequenication Proc ...
- windows 平台安装 ffmpeg
一.从https://ffmpeg.zeranoe.com/builds/中下载ffmpeg的static版本: 二.将下载下来的“ffmpeg-4.0.2-win64-static.zip”解压到任 ...
- docker实现跨主机连接
实验环境: centos7系统 host1:192.168.42.128 host2:192.168.42.129 dokcer容器跨主机连接 1.使用网桥实现跨主机容器连接 2.使用Open vSw ...
- FileZilla-FTP连接失败
状态: 已登录状态: 读取“/”的目录列表...命令: CWD /响应: 250 CWD successful. "/" is current directory.命令: TYPE ...
- ifconfig命令详情
基础命令学习目录首页 原文链接:https://blog.csdn.net/weixin_37886382/article/details/79716879 许多windows非常熟悉ipconfig ...
- SpringBoot集成dubbo实例
项目总览图: 最下面有项目的pom,具体内容: 项目运行注意事项: 先启动 provider, 将providers.xml中 port 先修改为20187 执行test目录 下的DubboProvi ...
- No.1_NABCD模型分析
Reminder 之 NABCD模型分析 定位 多平台的闹钟提醒软件. 在安卓市场发布软件,发布后一周的用户量为1000. N (Need 需求) 这个 ...
- ### Error building SqlSession.
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error may e ...
- spring冲刺第三天
昨天完成了环境配置和初步的地图设想. 今天从网上找了有关这方面的例子,运行试验了一番.编写的地图画面在程序上运行了一下,有些错误,还需要很多方面的改进. 这些例子有很多地方都不太懂,但还是看完了.我认 ...