POJ1151+线段树+扫描线
/*
线段树+扫描线+离散化
求多个矩形的面积
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
using namespace std;
const int maxn = ;
const int maxm = ;
struct SegTree{
int l,r;
int cover;
double L_val,R_val;
double sum;
}ST[ maxm<< ];
struct Line{
double x,y1,y2;
bool InOut;
}yLine[ maxm ];
int cmp( Line a,Line b ){
return a.x<b.x;
}
double yIndex[ maxm ];
int GetIndex( double val,int cnt ){
return lower_bound( yIndex,yIndex+cnt,val )-yIndex;
} void build( int L,int R,int n ){
ST[ n ].l = L;
ST[ n ].r = R;
ST[ n ].cover = ;
ST[ n ].sum = ;
ST[ n ].L_val = yIndex[ L ];
ST[ n ].R_val = yIndex[ R ];
if( R-L> ){
int mid = (L+R)/;
build( L,mid,*n );
build( mid,R,*n+ );
}
}
void PushUp( int n ){
if( ST[ n ].cover> ){
ST[ n ].sum = ST[ n ].R_val-ST[ n ].L_val;
}
else if( ST[ n ].r-ST[ n ].l> ){
ST[ n ].sum = ST[ *n ].sum+ST[ *n+ ].sum;
}
else
ST[ n ].sum = ;
}
void update( int left,int right,bool InOut,int n ){
if( left==ST[ n ].l&&right==ST[ n ].r ){
if( InOut==true ){
ST[ n ].cover++;
}
else{
ST[ n ].cover--;
}
}
else {
int mid = (ST[ n ].l+ST[ n ].r)/;
if( mid>=right ) update( left,right,InOut,*n );
else if( mid<=left ) update( left,right,InOut,*n+ );
else {
update( left,mid,InOut,*n );
update( mid,right,InOut,*n+ );
}
}
PushUp( n );
} int main(){
int n;
int T = ;
while( scanf("%d",&n)==,n ){
printf("Test case #%d\n",T++);
double x1,y1,x2,y2;
int cnt = ;
for( int i=;i<n;i++ ){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
yLine[ *i ].x = x1;
yLine[ *i+ ].x = x2;
yLine[ *i ].y1 = yLine[ *i+ ].y1 = y1;
yLine[ *i ].y2 = yLine[ *i+ ].y2 = y2;
yLine[ *i ].InOut = true;
yLine[ *i+ ].InOut = false;
yIndex[ *i ] = y1;
yIndex[ *i+ ] = y2;
}
sort( yLine,yLine+*n,cmp );
sort( yIndex,yIndex+*n );
for( int i=;i<*n;i++ ){
if( yIndex[i]!=yIndex[i-] )
yIndex[ cnt++ ] = yIndex[ i- ];
}
yIndex[ cnt++ ] = yIndex[ *n- ];
build( ,cnt-, );
double res = ;
update( GetIndex( yLine[].y1,cnt ),GetIndex( yLine[].y2,cnt ),yLine[].InOut, );
for( int i=;i<*n;i++ ){
res += ST[ ].sum*( yLine[i].x-yLine[i-].x );
update( GetIndex( yLine[i].y1,cnt ),GetIndex( yLine[i].y2,cnt ),yLine[i].InOut, );
}
printf("Total explored area: %.2lf\n\n",res);
}
return ;
}
POJ1151+线段树+扫描线的更多相关文章
- Atlantis poj1151 线段树扫描线
Atlantis poj1151 线段树扫描线 题意 题目给了n个矩形,每个矩形给了左下角和右上角的坐标,矩形可能会重叠,求的是矩形最后的面积. 题解思路 这个是我线段树扫描线的第一题,听了学长的讲解 ...
- Atlantis(POJ1151+线段树+扫描线)
题目链接:http://poj.org/problem?id=1151 题目: 题意:求所有矩形的面积,重合部分只算一次. 思路:扫描线入门题,推荐几篇学扫描线的博客: 1.http://www.cn ...
- 【学习笔记】线段树—扫描线补充 (IC_QQQ)
[学习笔记]线段树-扫描线补充 (IC_QQQ) (感谢 \(IC\)_\(QQQ\) 大佬授以本内容的著作权.此人超然于世外,仅有 \(Luogu\) 账号 尚可膜拜) [学习笔记]线段树详解(全) ...
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
随机推荐
- 设置win7任务栏显示标题,而不显示缩略图
win7系统的任务栏可以显示桌面缩略图,这是非常好的一个功能,但是有时候我们希望只显示标题,如下所示 怎样设置呢?只要在桌面上的计算机图标上面“右键”,选择“属性”,在弹出的窗口选择“高级系统设置”, ...
- 分布式系统怎样体现了CAP
`references:` 1. http://zh.wikipedia.org/wiki/CAP%E5%AE%9A%E7%90%86 2. http://en.wikipedia.org/wiki/ ...
- ZipArchive 的使用
新建一个项目,首先添加 System.IO.Compression.FileSystem 引用. 解压文件 using System.IO.Compression; namespace cl { st ...
- ICallbackEventHandler 接口实现回调处理功能
在最近的项目实现中遇到了一个问题 在数据处理的过程中,需要请求获取数据,再做处理之后,可以在页面及时获取数据 开始时,首先想到的到是写Ajax请求,但在做后续数据处理后,处理获取数据等操作,感觉实现起 ...
- Item47
STL迭代器分类:input迭代器.output迭代器.forward迭代器.bidirectional迭代器.random access迭代器. Input迭代器:只能向前移动,一次一步,客户只读取 ...
- =====关于swing的一些收集-swing大收集======
一篇经典的 介绍netbeans中swing 应用程序框架的文章 http://blog.csdn.net/tangwing/article/details/5745075 Swing外观框架 Bea ...
- 利用Google GCM发送push通知到Android客户端
// 这个可以需要在google账号中申请,勾选gcm服务选项 $apiKey = 'AIzaSyC6h3ysrn2HDCBqONTo2vKIVVuktIFoxxx'; $headers = arra ...
- DOM基础总结
一.简介 1.什么是DOM 文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式 ...
- 【刷机】Google Nexus s 蓝牙点击异常,无法启动,刷机解决方案
1 问题详述 手头上有一部Google Nexus S ,本机自带的输入法不好用,想下载其他的输入法,想用蓝牙传输一下apk文件,点了一下蓝牙开关想要打开蓝牙功能,但奇怪的情况出现了,手机一直重启, ...
- ubuntu12.04 server + apache2 + wsgi + django1.6 部署
最近在学Python和Django,想自己部署一个服务器试试 环境:ubuntu12.04 server | apache2 | django1.6 | python2.7 | mod_wsgi 在网 ...