P - Atlantis - hdu1542(求面积)
题意:rt 求面积......不计算重复面积(废话。。)hdu1255 的弱化版,应该先做这道题在做那道题的。
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; #define Lson r<<1
#define Rson r<<1|1 const int MAXN = 1e5+; struct segmentTree
{///cover记录本区间是否被覆盖,len记录被覆盖的长度
int L, R, cover;
double len;
int mid(){return (L+R)>>;}
}a[MAXN<<];
double Hash[MAXN]; int nh;///记录离散化后的数据
///记录矩形的y边,dir等1表示左边, -1表示右边
struct Edge{double x, y1, y2; int dir;}e[MAXN];
bool cmp(Edge n1, Edge n2)
{///把边按照x从小往大排序
return n1.x < n2.x;
}
///求y边的长度
double FindEgeLen(int y1, int y2)
{///y1 < y2
return Hash[y2] - Hash[y1];
}
void BuildSegTree(int r, int L, int R)
{///建立紧密线段树
a[r].L = L, a[r].R = R;
a[r].len = a[r].cover = ; if(L == R-)return ; BuildSegTree(Lson, L, a[r].mid());
BuildSegTree(Rson, a[r].mid(), R);
}
void PushUp(int r)
{
if(a[r].cover)
a[r].len = FindEgeLen( a[r].L, a[r].R );
else if(a[r].L == a[r].R-)
a[r].len = ;
else
a[r].len = a[Lson].len + a[Rson].len;
}
void UpData(int r, int L, int R, int dir)
{
if(a[r].L == L && a[r].R == R)
{
a[r].cover += dir;
PushUp(r); return ;
} if(R <= a[r].mid())
UpData(Lson, L, R, dir);
else if(L >= a[r].mid())
UpData(Rson, L, R, dir);
else
{
UpData(Lson, L, a[r].mid(), dir);
UpData(Rson, a[r].mid(), R, dir);
} PushUp(r);
} int main()
{
int i, N, t=; while(scanf("%d", &N), N)
{
double x1, x2, y1, y2, area=; int k = ; nh = ; for(i=; i<N; i++)
{
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
e[k].x=x1, e[k].y1=y1, e[k].y2=y2, e[k++].dir=;
e[k].x=x2, e[k].y1=y1, e[k].y2=y2, e[k++].dir=-;
Hash[nh++] = y1, Hash[nh++] = y2;
} sort(Hash, Hash+nh);
nh = unique(Hash, Hash+nh)-Hash; BuildSegTree(, , nh-); sort(e, e+k, cmp); for(i=; i<k-; i++)
{
int L = lower_bound(Hash, Hash+nh, e[i].y1)-Hash;
int R = lower_bound(Hash, Hash+nh, e[i].y2)-Hash; UpData(, L, R, e[i].dir); area += a[].len * (e[i+].x - e[i].x);
} printf("Test case #%d\n", t++);
printf("Total explored area: %.2f\n\n", area);
} return ;
}
P - Atlantis - hdu1542(求面积)的更多相关文章
- hdu1542 Atlantis 线段树--扫描线求面积并
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- HDU 1255 覆盖的面积(线段树:扫描线求面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题目大意:给你若干个矩形,让你求这些矩形重叠两次及以上的部分的面积. 解题思路:模板题,跟HDU ...
- HDU 1542 Atlantis(矩形面积并)
HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...
- poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: ...
- HDU1542矩形面积并
取出纵向边按x坐标排序,在y方向上建立线段树. 每次查询当前有效长度len,ans += len*(x[i]-x[i-1]); 其中len为T[rt].len; 查询完毕后更新y方向上线段树,入边+1 ...
- 编写一个矩形类,私有数据成员为矩形的长( len)和宽(wid),wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取矩形的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。
class Rectangle { private double len, wid; public Rectangle()//求矩形周长 { len = 0; wid = 0; } public Re ...
- HDU - 1255 覆盖的面积 (线段树求面积交)
https://cn.vjudge.net/problem/HDU-1255 题意 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 分析 求面积并的题:https://www.cnbl ...
- 覆盖的面积 HDU - 1255(扫描线求面积交)
题意: 就是扫描线求面积交 解析: 参考求面积并.... 就是把down的判断条件改了一下..由w > 0 改为 w > 1 同时要讨论一下 == 1 时 的情况, 所以就要用到一个临时 ...
随机推荐
- 提高VS2010/VS2012编译速度
除了合理的划分模块,减少link的时间外,充分利用多核编译也很重要. VS2010/2012都可以用多核编译,需要同时设置如下两个参数: Enable Minimal Rebuild Propert ...
- [转] Ubuntu 12.04下LAMP安装配置 (Linux+Apache+Mysql+PHP)
我是一个Linux新手,想要安装一台Ubuntu 12.04版的Linux服务器,用这台服务器上的LAMP套件来运行我自己的个人网站.LAMP套件就是 “Linux+Apache+Mysql+PHP这 ...
- FastReport 动态修改连接字符串
代码如下: Report rp = new Report(); rp.Load(@"Print\aa.frx"); rp.Dictionary.Connections[0].Con ...
- state模式理解
state模式应用场景 条件判断很多的情况 比如有很多if else语句:switch case语句等等. 如果以后业务越来越复杂,条件判断有100多个,每种条件的处理逻辑很复杂,不止一个业务逻辑会重 ...
- SpringBoot入门系列:第一篇 Hello World
跟随SpringBoot的文档(http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-d ...
- 利用eclipse开发php<转>
1.安装php环境 Eclipse支持PHP自动提示 其实如果你已经安装好了php环境(安装过程见)的话,只需要下面2步就可以了.hoho,很简单的. 1,下载eclipse中php的插件phpecl ...
- 关于.net类型转换判断问题
做项目时,发现这个问题,由于数据库中的字段可能为null,如果在.net程序直接转换时,比如 ltTime.Text =DateTime.Parse(dt.Rows[0]["m_Time&q ...
- SQL从入门到基础–03 SQLServer基础1(主键选择、数据插入、数据更新)
一.SQL语句入门 1. SQL语句是和DBMS“交谈”专用的语句,不同DBMS都认SQL语法. 2. SQL语句中字符串用单引号. 3. SQL语句中,对于SQL关键字大小写不敏感,对于字符串值大小 ...
- C++中类成员使用前需要初始化的重要性
今天写程序的时候,创建了一个结构体: struct BufferObj { char* buf; int bufLen; SOCKADDR_STORAGE addr; int addrLen; str ...
- C++ 性能剖析 (二):值语义 (value semantics)
Value Semantics (值语义) 是C++的一个有趣的话题. 什么是值语义? 简单的说,所有的原始变量(primitive variables)都具有value semantics. 也可以 ...