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. 

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 (线段树+矩阵面积并+离散化)的更多相关文章

  1. hdu1542 Atlantis 线段树--扫描线求面积并

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

  2. 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 ...

  3. hdu1542(线段树——矩形面积并)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 分析:离散化+扫描线+线段树 #pragma comment(linker,"/STA ...

  4. hdu 1542 线段树扫描(面积)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. 2017ICPC南宁赛区网络赛 Overlapping Rectangles(重叠矩阵面积和=离散化模板)

    There are nnn rectangles on the plane. The problem is to find the area of the union of these rectang ...

  6. Wannafly Winter Camp 2019.Day 8 div1 E.Souls-like Game(线段树 矩阵快速幂)

    题目链接 \(998244353\)写成\(99824435\)然后调这个线段树模板1.5h= = 以后要注意常量啊啊啊 \(Description\) 每个位置有一个\(3\times3\)的矩阵, ...

  7. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  8. HDU - 1542 Atlantis(线段树求面积并)

    https://cn.vjudge.net/problem/HDU-1542 题意 求矩形的面积并 分析 点为浮点数,需要离散化处理. 给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1).(x ...

  9. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

随机推荐

  1. 关于Myeclipse的MyEclipse:Java was started but returned exit code=-1 错误

    我们在安装MyEclipse后有时会遇到这样一个问题,可以进入主界面软件也属于激活状态,但是过一会会报错, 并弹出MyEclipse:Java was started but returned exi ...

  2. 用人工智能学习,凡亿推出PCB问题解答智能搜索机器人:pcb助手

    对于学习者,你是不是经常遇到这样的问题:在我们狠狠下定决心学习PCB技术的时候,我们常常遇到很多大大小小的问题,遗憾的是身边没有一个能及时给自己解答问题的高手指点,通过论坛.群等方式询问可能半天也得不 ...

  3. 利用for循环如何判定是水仙花数

    水仙花数业内的大家可能听说过,但是对于初学者来讲,对于水仙花数还是比较陌生的. 首先要知道的是水仙花数的计算公式:153=1**3+5**3+3**3: 如何去判定这个数是否为水仙花数,最好的办法就是 ...

  4. WebGL——水波纹特效

    大家好,今天我ccentry要做一个水波纹特效,我们来看看水波纹特效的做法.首先我们来看一下水波纹特效的效果是怎么样的,请看下图. 我们要做的就是类似这种纹理特效,那么我们来看看是如何制作的吧.首先鲫 ...

  5. Kubernetes服务发现之Service详解

    一.引子 Kubernetes Pod 是有生命周期的,它们可以被创建,也可以被销毁,然后一旦被销毁生命就永远结束.通过ReplicationController 能够动态地创建和销毁Pod(列如,需 ...

  6. vue-scroller实现vue单页面的上拉加载和下拉刷新问题

    在vue中如何简单的实现页面的上拉加载和下拉刷新,在这里我推荐使用vue-scrolle插件. vue-scrolle的基本使用方法: 1.下载 npm i vue-scroller -D 2.导包 ...

  7. 粒子群算法(PSO)关于参数w的一些改进方法

    (一)线性递减 function [xm,fv] = PSO_lin(fitness,N,c1,c2,wmax,wmin,M,D) format long; % fitness学习函数 % c1学习因 ...

  8. C++ 学习笔记 变量和基本类型(一)

    C++ 学习笔记 一.变量和基本类型概述 类型是所有程序的基础.类型告诉我们数据代表什么意思以及可以对数据执行哪些操作. c++基本类型: 字符型 整型 浮点型 c++ 还提供了可用于自定义数据类型的 ...

  9. mysql的安装教程-【linux】

    先卸载系统自带的mysql,停止mysql:service mysql stop 1.查找以前是否装有mysql命令:rpm -qa|grep -i mysql可以看到mysql的几个包:qt-mys ...

  10. 最新的CocoaPods 安装及使用

    当在开发iOS应用时,会经常使用到很多的第三方开源类库,一般的方法是直接从GitHub下载,然后拖到项目中使用,如果该开源类库不依赖其他的类库,就可以直接使用:如果该开源类库还依赖一些其他的类库,则需 ...