Atlantis HDU - 1542 (扫描线,线段树)
扫描线的模板题,先把信息接收,然后排序,记录下上边和下边,然后用一条虚拟的线从下往上扫。如果我扫到的是下边,那么久用线段树在这个区间内加上1,表示这个区间现在是有的,等我扫描到上边的时候在加上-1,把之前的消掉,然后线段树维护区间内的长度,这里不是直接用下标维护,而是需要另一个数组来维护,每次记录我当前的下标在原本的图中的长度。
在update部分用一个点表示我这个点以后的一个长度为1的区间,然后这样算出来的sum[1]就是我现在线段树里包括的区间大小,然后用现在的区间大小去乘上这一部分的高度,然后每次相加,就可以了
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int n, m, tol, T;
struct Node {
double l, r, h;
int f;
bool operator <(Node a) const {
return h < a.h;
}
};
Node node[maxn];
double a[maxn];
double sum[maxn << ];
int cnt[maxn << ]; void init() {
memset(sum, , sizeof sum);
memset(cnt, , sizeof cnt);
} void pushup(int left, int right, int root) {
if(cnt[root] != ) sum[root] = a[right + ] - a[left];
else if(left == right) sum[root] = ;
else sum[root] = sum[root << ] + sum[root << | ];
} void update(int left, int right, int prel, int prer, int val, int root) {
if(prel <= left && right <= prer) {
cnt[root] += val;
pushup(left, right, root);
return ;
}
int mid = (left + right) >> ;
if(prel <= mid) update(left, mid, prel, prer, val, root << );
if(prer > mid) update(mid+, right, prel, prer, val, root << | );
pushup(left, right, root);
} int main() {
int cas = ;
while(scanf("%d", &n)== && n) {
init();
double x1, y1, x2, y2;
for(int i=; i<=n; i++) {
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
node[*i-].l = x1;
node[*i].l = x1;
node[*i-].r = x2;
node[*i].r = x2;
node[*i-].h = y1;
node[*i].h = y2;
node[*i-].f = ;
node[*i].f = -;
a[*i-] = x1;
a[*i] = x2;
}
n = *n;
sort(node+, node++n);
sort(a+, a++n);
int nn = unique(a+, a++n) - (a+);
double ans = ;
for(int i=; i<n; i++) {
int l = lower_bound(a+, a++nn, node[i].l) - a;
int r = lower_bound(a+, a++nn, node[i].r) - a;
update(, nn, l, r-, node[i].f, );
ans += (node[i+].h - node[i].h) * sum[];
}
printf("Test case #%d\n", cas++);
printf("Total explored area: %0.2f\n", ans);
printf("\n");
}
return ;
}
Atlantis HDU - 1542 (扫描线,线段树)的更多相关文章
- Atlantis HDU - 1542 (线段树扫描线)
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- HDU 1542 Atlantics 线段树+离散化扫描
将 x 轴上的点进行离散化,扫描线沿着 y 轴向上扫描 每次添加一条边不断找到当前状态有效边的长度 , 根据这个长度和下一条边形成的高度差得到一块合法的矩形的面积 #include<iostre ...
- hdu 1542(线段树+扫描线 求矩形相交面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- poj 1151 Atlantis (离散化 + 扫描线 + 线段树 矩形面积并)
题目链接题意:给定n个矩形,求面积并,分别给矩形左上角的坐标和右上角的坐标. 分析: 映射到y轴,并且记录下每个的y坐标,并对y坐标进行离散. 然后按照x从左向右扫描. #include <io ...
- 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543
学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...
- 线段树扫描线(一、Atlantis HDU - 1542(覆盖面积) 二、覆盖的面积 HDU - 1255(重叠两次的面积))
扫描线求周长: hdu1828 Picture(线段树+扫描线+矩形周长) 参考链接:https://blog.csdn.net/konghhhhh/java/article/details/7823 ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)
Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...
- hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积
题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
随机推荐
- Django 组件之 ----- content-type
Django 组件之 content-type的使用 一个表和多个表进行关联,但具体随着业务的加深,表不断的增加,关联的数量不断的增加,怎么通过一开始通过表的设计后,不在后期在修改表,彻底的解决这个问 ...
- 如何在 Linux 中查找最大的 10 个文件
https://linux.cn/article-9495-1.html
- 4 HttpServletResponse 与 HttpServletRequest
Web 服务器收到一个http请求,会针对每个请求创建一个HttpServletRequest 和 HttpServletReponse 对象,response用于向客户端发送数据,request用于 ...
- 2 Interrupting Appropriately
1 Interrupting someone politely e.g. Excuse me for interrupting, but may I ask a question? Sure. Of ...
- mybatis出现NoSuchMethodException异常
今天在idea中调试项目(ssm搭建的项目)的时候,mybatis突然出现了NoSuchMethodException异常,具体的异常时: java.lang.NoSuchMethodExceptio ...
- js关闭当前页
/*关闭当前页*/ function closeCurrentPage() { var userAgent = navigator.userAgent; if (userAgent.indexOf(& ...
- eclipse 部署项目
- nginx反向代理proxy_pass的问题
起因:今天企业部署一个项目,用的nginx做的反向代理,配置如下: 测试结果令人失望,IP:端口 能访问项目,域名:端口 也能访问 ,但是 域名/接口名 访问失败 ################## ...
- WhiteHat Contest 11 : re1-100
ELF文件,运行一下是要求输密码 die查了一下无壳 直接拖入ida 可以发现 这是它的判断函数 也就是说输入的总长度是42位第一个字符是123也就是0x7b 也就是'{'然后10位是"53 ...
- cookie的域,路径
Cookie 的路径以及 Cookie 域 cookie 路径 cookie 一般都是由于用户访问页面而被创建的,可是并不是只有在创建 cookie 的页面才可以访问这个cookie.在默认情况下,出 ...