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 ...
随机推荐
- Javascript深入__proto__和prototype的区别和联系
有一个一个装逼的同事,写了一段代码 function a(){} a.__proto__.__proto__.__proto__ 然后问我,下面这个玩意a.__proto__.__proto__.__ ...
- day05 字典 dict
今日内容: 字典 成对的保存数据. 以key:value的形式保存 用{}表示,每一项内容都是key:value, 每项数据之间用逗号隔开 字典中的key是不能重复的. 存储是依靠着key来计算的. ...
- leetcode12_C++整数转罗马数字
小弟不才,有错误或者更好解,求留言. 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, ...
- conda环境管理
查看环境 conda env list 创建环境 conda create -n python36 python=3.6 进入环境 source activate python36 activate ...
- mysql查看锁表与解锁
查看锁表语句 show OPEN TABLES where In_use > 0; 找到锁表的进程 show processlist; 删除锁表进程 kill 51045123;
- KETTLE元数据表
表名 说明 R_CLUSTER R_CLUSTER_SLAVE R_CONDITION R_DATABASE 数据库连接信息 R_DATABASE_ATTRIBUTE 数据库属性 R_DATABASE ...
- 哈夫曼(Huffman)树+哈夫曼编码
前天acm实验课,老师教了几种排序,抓的一套题上有一个哈夫曼树的题,正好之前离散数学也讲过哈夫曼树,这里我就结合课本,整理一篇关于哈夫曼树的博客. 主要摘自https://www.cnblogs.co ...
- Java访问控制
转自:菜鸟教程
- .net组件和com组件&托管代码和非托管代码
com组件和.net组件: COM组件是非托管对象,可以不需要.NET框架而直接运行,.NET框架组件是托管对象,必须有.NET框架的支撑才能运行. COM组件有独立的类型库文件,而.NET组件是通过 ...
- CSS3:不可思议的border属性
在CSS中,其border属性有很多的规则.对于一些事物,例如三角形或者其它的图像,我们仍然使用图片代替.但是现在就不需要了,我们可以用CSS形成一些基本图形,我分享了一些关于这方面的技巧. 1.正三 ...