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 时 的情况, 所以就要用到一个临时 ...
随机推荐
- Java基础知识强化72:正则表达式之判断功能(手机号码判断 和 校验邮箱)
1. 判断功能: 使用了String类的matches方法,如下: public boolean matches(String regex): 2. 判断手机号码的案例: package cn.it ...
- php 时间转换
在数据库读出的数据,都是字符类型的,所以需要转换: 时间的转换:用date ()函数来实现时间格式; date() 函数默认时间是1970/01/01/ 00:00:00; 要想得到想要的时间就还得用 ...
- 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】
2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...
- mui实现退出当前应用
var first = null; var showMenu = false; mui.back = function() { if(showMenu) { closeMenu();} else { ...
- java克隆总结
对象clone,注意基本类型和指针类型.
- sharepoint2013小技巧
一.创建基于经典认证的应用程序 New-SPWebApplication -Name "Contoso Internet Site" -ApplicationPool " ...
- asp.net微信开发第九篇----模板消息的使用
微信平台的模板消息,使用起来非常好,效果如下: 和平时我们微信中关注信用卡官方微信,如果消费了,信用卡官方微信就返回一个模板消息给我们告知,余额还有多少,消费了多少. 使用的步骤,我只简单介绍了怎么使 ...
- Linux samba服务器设置简单匿名共享
linux下面的samba非常的好用,很多人拿它来作共享文件服务器, 缺省配置下,samba必须提供用户名密码来访问,如果是所有人都可以访问的内容,那么是比较麻烦的,其实通过一个设置,即可实现不用输入 ...
- 配置Windows Server 2008 允许多用户远程桌面连接
开启远程桌面后,远程访问windows server 2008服务器时,默认只支持一个用户名同时只能创建一个远程连接,新建连接登录后会将前一个就踢掉,有没有办法像windows server 2005 ...
- eclipse sae上传代码
eclipse sae上传代码http://www.sinacloud.com/doc/sae/java/tools.html#eclipse 来自为知笔记(Wiz)