描述
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.
Input
The 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.

 
Output
For 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
题意
给你N个矩形,每个矩形的左下和右上的点,求面积并
题解
由于点不是很多,可以对x轴进行离散化,去重
线段树面积并
代码

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N=; int col[N<<];
double sum[N<<],x[N<<]; struct seg
{
double l,r,h;
int s;
seg(){}
seg(double l,double r,double h,int s):l(l),r(r),h(h),s(s){}
bool operator<(const seg &D)const{
return h<D.h;
}
}s[N];
void PushUp(int rt,int l,int r)
{
if(col[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)
{
col[rt]+=C;
PushUp(rt,l,r);
return;
}
int mid=(l+r)>>;
if(L<=mid)Update(L,R,C,l,mid,rt<<);
if(R>mid)Update(L,R,C,mid+,r,rt<<|);
PushUp(rt,l,r);
}
int main()
{
int n,o=;
double a,b,c,d;
while(~scanf("%d",&n),n)
{
int cnt=;
for(int i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
s[++cnt]=seg(a,c,b,);
x[cnt]=a;
s[++cnt]=seg(a,c,d,-);
x[cnt]=c;
}
sort(x+,x++cnt);
sort(s+,s++cnt);
int k=;
for(int i=;i<=cnt;i++)
if(x[i]!=x[i-])
x[++k]=x[i]; memset(sum,,sizeof sum);
memset(col,,sizeof col);
double ans=;
for(int i=;i<cnt;i++)
{
int l=lower_bound(x+,x++k,s[i].l)-x;
int r=lower_bound(x+,x++k,s[i].r)-x-;
Update(l,r,s[i].s,,k,);
ans+=sum[]*(s[i+].h-s[i].h);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",o++,ans);
}
return ;
}
 

HDU 1542 Atlantis(线段树面积并)的更多相关文章

  1. POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并

    题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...

  2. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  3. hdu 1542 Atlantis(线段树,扫描线)

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

  4. hdu 1542 Atlantis (线段树扫描线)

    大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...

  5. HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)

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

  6. HDU 1542 Atlantis(矩形面积并)

    HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...

  7. hdu 1542 Atlantis(段树&amp;扫描线&amp;面积和)

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

  8. HDU 1542 Atlantics 线段树+离散化扫描

    将 x 轴上的点进行离散化,扫描线沿着 y 轴向上扫描 每次添加一条边不断找到当前状态有效边的长度 , 根据这个长度和下一条边形成的高度差得到一块合法的矩形的面积 #include<iostre ...

  9. Atlantis HDU - 1542 (线段树扫描线)

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

随机推荐

  1. windowsAPI之OpenProcessToken,AdjustTokenPrivileges 和LookupPrivilegeValue<转>

    这三个函数主要用来提升进程的权限 1 OpenProcessToken()函数:获取进程的令牌句柄 OpenProcessToken的原型. BOOL WINAPI OpenProcessToken( ...

  2. Struts2中使用HttpServletRequest和HttpServletResponse

    一.非Ioc方式 这种方式主要是利用了com.opensymphony.xwork2.ActionContext类以及org.apache.struts2.ServletActionContext类, ...

  3. li直接1px 像素的原因

    1.由于空白节点(多由于Enter造成),li不换行就可以解决问题. Internet Explorer会忽略节点之间生成的空白节点,其它浏览器不会忽略(可以通过检测节点类型,过滤子节点) 2.完美解 ...

  4. AWK 知识库

    awk 极客课程 <AWK 编程语言>1 <AWK 编程语言>2 <AWK程序设计语言>https://github.com/wuzhouhui/awk http: ...

  5. data型怎么转换格式

    data型如何转换格式01-1月   -03       如何转成   YYYY-MM-DD   的格式 本来就是date了 ------解决方案--------------------to_char ...

  6. 用crash来分析一下proc的文件访问

    一般来说,用户通过fd的传入,调用open系统调用,来获取fd,然后read的时候,通过这个fd来查找对应的file* SYSCALL_DEFINE3(open, const char __user ...

  7. matt cutts : try something new for 30 days

    30 天尝试新事物matt cutts : try something new for 30 days[小计划帮你实现大目标] 是否有些事情, 你一直想去做, 但就是没有实现?马特 ?卡茨建议: 尝试 ...

  8. avalon2学习教程06样式操作

    avalon2的ms-css的变革思路与ms-attr一样,将多个操作合并成到一个对象里面处理,因此没有ms-css-name="value",只有ms-css="Obj ...

  9. 为了显示此页面,Firefox 必须发送将重复此前动作的数据(例如搜索或者下订单)

    火狐浏览器重新加载页面出现下面提示,必须要点击“重新发送”才能完成刚才的请求: 这个是火狐的一个提示功能主要是防止同一页面的数据反复提交: 解决方法: 不要用location.reload();来刷新 ...

  10. Structs复习 Path问题

    Path问题相对复杂 主要是路劲问题 但结论很简单 就是统一使用绝对路径 jar包 web.xml <?xml version="1.0" encoding="UT ...