Hdu1542 Atlantis
Atlantis
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15236 Accepted Submission(s): 6265
The input file is terminated by a line containing a single 0. Don’t process it.
Output a blank line after each test case.
10 10 20 20
15 15 25 25.5
0
Total explored area: 180.00
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = ; struct node
{
double l, r, h;
int id;
}e[maxn]; double X[maxn], c[maxn << ], XX[maxn], ans;
int cnt, n, tot, tag[maxn << ], cas = ; bool cmp(node a, node b)
{
return a.h < b.h;
} int find(double x)
{ int l = , r = cnt, res = cnt - ;
while (l <= r)
{
int mid = (l + r) >> ;
if (X[mid] >= x)
{
res = mid;
r = mid - ;
}
else
l = mid + ;
}
return res;
} void pushup(int o, int l, int r)
{
if (tag[o])
c[o] = X[r + ] - X[l];
else
if (l == r) //没有被完全覆盖就是两个点
c[o] = ;
else
c[o] = c[o * ] + c[o * + ];
} void update(int o, int l, int r, int x, int y, int v)
{
if (x <= l && r <= y)
{
tag[o] += v;
pushup(o, l, r);
return;
}
int mid = (l + r) >> ;
if (x <= mid)
update(o * , l, mid, x, y, v);
if (y > mid)
update(o * + , mid + , r, x, y, v);
pushup(o, l, r);
} int main()
{
while (~scanf("%d", &n) , n)
{
memset(c, , sizeof(c));
memset(tag, , sizeof(tag));
ans = 0.0;
tot = cnt = ;
for (int i = ; i <= n; i++)
{
double a, b, c, d;
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
e[++tot].l = a;
e[tot].r = c;
e[tot].h = b;
e[tot].id = ;
X[tot] = a;
e[++tot].l = a;
e[tot].r = c;
e[tot].h = d;
e[tot].id = -;
X[tot] = c;
}
sort(X + , X + tot + );
sort(e + , e + + tot, cmp);
XX[] = X[];
cnt = ;
for (int i = ; i <= tot; i++)
if (X[i] != X[i - ])
XX[++cnt] = X[i];
memcpy(X, XX, sizeof(XX));
for (int i = ; i < tot; i++)
{
int l = find(e[i].l), r = find(e[i].r) - ;
update(, , cnt, l, r, e[i].id);
ans += c[] * (e[i + ].h - e[i].h);
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n", cas++, ans);
} return ;
}
Hdu1542 Atlantis的更多相关文章
- hdu1542 Atlantis(矩阵面积的并)
这个题算是我的第一个扫描线的题,扫描线算是一种思想吧,用到线段树+离散化.感觉高大上. 主要参考了这位大神的博客. http://www.cnblogs.com/kuangbin/archive/20 ...
- HDU1542 Atlantis —— 求矩形面积并 线段树 + 扫描线 + 离散化
题目链接:https://vjudge.net/problem/HDU-1542 There are several ancient Greek texts that contain descript ...
- hdu1542 Atlantis 线段树--扫描线求面积并
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- hdu1542 Atlantis (线段树+扫描线+离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu1542 Atlantis (线段树+矩阵面积并+离散化)
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- [HDU1542]Atlantis(扫描线+线段树)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu-1542 Atlantis(离散化+线段树+扫描线算法)
题目链接: Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU-1542 Atlantis(离散化+扫描线)
题目大意:给n个矩形,可能重叠,求面积. 题目分析:线段树维护扫描线. 代码如下: # include<bits/stdc++.h> using namespace std; # defi ...
- HDU1542 Atlantis(矩形面积并)
#pragma warning (disable:4996) #include<iostream> #include<cstring> #include<string&g ...
随机推荐
- eclipse 简单操作
1.设置字体: windows --> preferences --> general --> Colors and Fonts --> Basic --> 双击 Tex ...
- hibernate.hbm.xml文件配置入门小结(1)
在Hibernate中,各表的映射文件xxx.hbm.xml可以通过工具生成,例如在使用MyEclipse开发时,它提供了自动生成映射文件的工具. hibernate.hbm.xml文件的基本结构如下 ...
- 【探路者】团队中的每一次感动——Alpha版
我是[探路者]团队的leader翟宇豪.在软件工程课程开始时,当听说有团队作业这个任务时,我个人还是对leader这个角色很期待的.我很希望通过自己的努力,让我所在的团队变得更好,让组里的每一个成员在 ...
- python 读取blob
for num in range(76802): # if num == 0: # c[num] = imagedata[0:4] # d[num] = struct.unpack('i', c[nu ...
- Alpha-end
前言 失心疯病源10 团队代码管理github 个人感悟 肝不动了,肝不动了.明天如果见不到我,不要太想我. 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 熬夜肝代码 代码签入git ...
- 0302IT行业虽吃香,能完全享受这块“香"的也很难
面对现今严峻的就业形势,越来越多的人希望通过职业技能培训或者学历提升来提高自己的综合技能以便能够顺利地应聘到自己理想中的工作. 在2014年十大最热门行业和职业排行榜中IT行业最吃香.在十大行业里,I ...
- RAD Studio 10.3 Rio (BCB & Dephi) 发布啦
期盼已久的RAD Studio 10.3 Rio 终于发布了: 下载链接:http://altd.embarcadero.com/download/radstudio/10.3/delphicbui ...
- Spring mvc 数据验证框架注解
@AssertFalse 被注解的元素必须为false@AssertTrue 被注解的元素必须为false@DecimalMax(value) 被注解的元素必须为一个数字,其值必须小于等于指定的最小值 ...
- el表达式作用域查找顺序 注意:当属性名字相同时候 先找到是小的作用域 因为是从小到大开始找的
- 【bzoj1502】[NOI2005]月下柠檬树 自适应Simpson积分
题目描述 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树旁,独自思索着人生的哲理.李哲是一个喜爱思考的孩子,当他看到在月 ...