HDU 1542 Atlantis(扫描线求矩形面积并+离散化)

扫描线(一)——求矩形面积并 前言 扫描线应该是一个很有用的算法。 它有许多用途,比较经典的应该就是用来求矩形面积并。 什么是矩形面积并 或许你会问,什么是矩形面积并? 在一个平面上,有若干个矩形,它们覆盖的总面积就是矩形面积并(重叠部分只算一次)。 要求矩形面积并,我们就可以用扫描线。 离散化 首先,我们要将这张图离散化预处理一下。 离散化的过程应该比较简单,将每个节点的坐标全部存在一个数组... 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=1542

题意就是给n个矩形,这些矩形可能存在覆盖的地方,求矩形面积并。这种题目要用到扫描线,同时还要用到离散化(一时因为数据特别大,二是因为题目中存在浮点数)。

扫描线:一根虚拟的线,从下往上(或者从左往右)扫所求的图形,如下图所示,一条从下往上的直线扫到该4条线,并将图形分成三个部分分别来求面积。

这里写图片描述

扫描线解法(从下往上):

  • 将扫到的边加入到segment结构体中,这个结构体中是这样的:
    struct segment
    {
    double x1,x2,y;
    int flag;
    }arr[N];
    每个边存上左端点x1,右端点x2,以及该条线处于的y值。
    同时要是该条边是矩形的下边,那么将flag置为1,上边置为-1(具体为什么下面再说)

  • 按照y值将结构体排序,从小到大的顺序

  • 将扫描到的线依次插入到线段树中并求值

线段树在扫描线算法中的意义:线段树的总区间如上图所示是整个图形在x轴上的投影。当扫描到n条线段时,我们只需要插入n-1条线段。刚开始一条线段都没插入时,整个线段树的每个节点的值都为0,每插入一条线段,这时候线段树记录的就是当前覆盖的线段长度,每插入一条线段时,就可以将ans更新,ans+=tr[1]*(arr[i+1].y-arr[i].y);

怎样计算当前覆盖的长度:这时候flag的作用体现出来了,同时还要借助一个cover数组用于记录当前线段树该节点是否被覆盖过的情况。刚开始,要memset(cover,0),每插入一条线段的时候,cover数组更新成:cover[i]+=flag;上面说了将一个矩形的下底边的flag置为1,将上边置为-1,当插入下底边的时候,当前节点的cover[i]=1,当再插入上边的时候,cover[i]+=-1此时就变成了0,和初始状态一样,这样就完美的完成了删除操作。再根据cover[i]的情况push_up;

介绍下push_up的操作:
如果当前节点的cover[i]==1,就说明当前该点表示的线段被覆盖了,那么tr[i] = 实际长度。
否则的话,说明这个点表示的长度并没有完全被覆盖,如果这个点是叶子节点,那么tr[i]=0,如果不是叶子节点,tr[i]就由下面的左右子结点推来。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define mset(x,y) memset(x,y,sizeof(x))
#define lson l,mid,i<<1
#define rson mid+1,r,i<<1|1
const int N = 200+10;
double has[N*2];//离散化数组
double tr[N*8];
int cover[N*8];

struct seg
{
    double x1,x2,y;
    int flag;
    friend bool operator < (const seg a,const seg b)
    {
        return a.y < b.y;
    }//将y值从小到大排序
}arr[N];
void pushup(int l,int r,int i)//very important!
{
    if(cover[i]) tr[i]= has[r+1]-has[l];
    else if(l==r) tr[i]=0;
    else tr[i]=tr[i<<1]+tr[i<<1|1];
    return;
}
void update(int l,int r,int i,int a,int b,int flag)
{
    if(l>=a&&r<=b)
    {
        cover[i]+=flag;
        pushup(l,r,i);
        return;
    }
    int mid=(l+r)>>1;
    if(mid>=a) update(lson,a,b,flag);
    if(mid<b) update(rson,a,b,flag);
    pushup(l,r,i);
    return;
}
int main()
{
    int n,cas=1;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        int t=0;
        for(int i=0;i<n;i++)
        {
            double x1,y1,x2,y2;
            scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
            arr[t].x1=x1,arr[t].x2=x2,arr[t].y=y1,arr[t].flag=1; //扫描边
            has[t]=x1;
            t++;
            arr[t].x1=x1,arr[t].x2=x2,arr[t].y=y2,arr[t].flag=-1;
            has[t]=x2;
            t++;
        }
        sort(arr,arr+t);
        sort(has,has+t);//离散化操作
        double ans=0;
        mset(tr,0);mset(cover,0);
        for(int i=0;i<t-1;i++)
        {
            int xx = lower_bound(has,has+t,arr[i].x1) - has ;
            int yy = lower_bound(has,has+t,arr[i].x2) - has - 1;
            if(xx<=yy) update(0,t-1,1,xx,yy,arr[i].flag);
            ans += tr[1]* (arr[i+1].y-arr[i].y);//更新ans
        }
        printf("Test case #%d\nTotal explored area: %.2lf\n\n",cas++,ans);
    }
    return 0;
}

关于push_up操作和cover数组要多理解 :)

Ubuntu中snap简单介绍 通过Snap可以安装众多的软件包。需要注意的是,snap是一种全新的软件包管理方式,它类似一个容器拥有一个应用程序所有的文件和库,各个应用程序之间完全独立。所以使用snap包的好处就是它解决了应用程序之间的依赖问题,使应用程序之间更容易管理。但是由此带来的问题就是它占用更多的磁盘空间 介绍一些常用命令,有点类似docker 1、查看已经通过snap安装的snap包 snap list可以查看 2、可以搜索想要的snap包,例如tomcat snap search tomcat 阅读详情

相关推荐

lighttools用透镜旋转手动创建菲尼尔透镜

学过很多软件,都没有留下痕迹,很多年之后只记得学过的软件常用的一些功能,稍微难一些的再次用起需要重新学,但如果留下点痕迹,重新再用就会很快。lighttools无意之中接触了,记一点点笔记吧。...

kingsai2012的博客 4342

HDU1542 Atlantis —— 求矩形面积并 线段树 + 扫描线 + 离散化

题目链接:https://vjudge.net/problem/HDU-1542 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 i...

alince20008的博客 170

基于N32G003的PMBus从机协议栈设计与STM32F103模拟I2C主机通信实战

本文详细介绍了基于N32G003微控制器设计PMBus从机协议栈,并与STM32F103模拟I2C主机进行通信的实战方案。重点阐述了中断驱动架构、命令解析、CRC8优化及超时恢复机制,实现了在70kHz速率下稳定可靠的工业电源管理通信,适用于服务器电源、通信基站等成本敏感应用场景。

numpy6sculptor的博客 927

HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板

好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解。现在来水一水博客,写一下若干年前的题目的题解。 Atlantis Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21978Accepted Submissio...

weixin_30776863的博客 132

MounRiver Studio实战:像管理个人项目一样整理沁恒MCU的EVT例程(附文件结构图)

本文详细介绍了如何使用MounRiver Studio重构沁恒MCU的EVT例程,实现工程化管理。通过分析官方EVT设计的局限性,提出标准化的目录结构和迁移步骤,帮助开发者提升代码可维护性和团队协作效率。文章还提供了MounRiver Studio的关键配置参数和常见问题排查指南,适用于沁恒MCU开发者。

weixin_33940469的博客 362

别再死记硬背菜单了!用Workbench搞定你的第一个ANSYS结构分析(附模型文件)

本文为零基础用户提供使用ANSYS Workbench完成第一个结构分析的完整指南。通过悬臂梁案例详细讲解从几何导入、材料定义、网格划分到边界条件设置的全流程,帮助初学者快速掌握有限元分析的基本操作,并附赠实用模型文件。

weixin_34233974的博客 316

HDU - 1542 Atlantis 面积并

HDU - 1542 Atlantis 第一次做扫描线,感觉很懵逼,思路很好理解,但代码实现完全想不到。。。 不会的可以看这:算法总结:【线段树+扫描线】&amp;矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) 用1标记下边,-1标记上边是最合理的(想想为什么,提示:下边--插入,上边--删除) 这题横坐标略大,需要离散化处理   现在假设有两个区间段:1——2——3...

没有梦想何以远行 228

RDMA性能调优实战:如何用ib_*命令榨干你的Mellanox网卡带宽?

本文深入探讨了如何利用ib_*命令工具集对RDMA网络进行深度性能调优,以充分释放Mellanox网卡的带宽潜力。文章从理解Send/Write/Read三种核心通信原语的差异入手,逐步指导读者通过调整消息大小、队列深度、内联数据等关键参数,并结合系统级的NUMA绑定、中断亲和性等优化策略,实现从基准测试到逼近硬件极限的性能提升。

weixin_29306011的博客 95

HDU1542 Atlantis 扫描线求矩形面积并 模板题

题意:给你平面内一些矩形的位置和大小,让你求面积之并(能看到的面积之和)。 思路:扫描线板子题,自己最开始看了看扫描线实现的思路自己莽着写了一个竟然过了,但是后来证明是这个题数据量小,但是数据量一大就会T掉。。。 所以老老实实又重新学了一遍扫描线。其实就是updata函数写的不对,总体思路还是离散化、建树、求面积。 要注意这里有一个小难点就是点和区间的对应。值得仔细琢磨一下。 #include&l...

枚举星星 230

YOLOv11改进 | 损失函数改进篇 | 2024最新高质量的目标检测边界框回归损失Unified-IoU、FocalUIoU、FocalInvUIoU(设置动态epoch参数)

本文给大家带来的改进机制是最近新提出的高质量的目标检测边界框回归损失,其通过动态调整模型对不同质量预测框的关注,优化目标检测中的边界框回归精度。UIoU引入了FocalBox方法,通过缩放预测框与真实框分配权重,并采用了退火策略(引入动态参数epoch),逐渐将模型的注意力从低质量预测框转移到高质量预测框,平衡了训练速度与检测精度。其还有一定的解决样本不平衡问题,同时该损失函数可以和现有的任何边界框回归损失函数进行结合,例如ShapeIoU和其结合可以形成二次创新,它是一种类似于之前的Inner的机制.

Snu77的博客 4608

ChatGPT辅助课题申报书研究背景部分的写作全过程指南

ChatGPT辅助课题申报书研究背景部分的写作全过程指南

智能AI让学术科研更容易 2564

HDU 1542 Atlantis(线段树扫描线)

http://acm.hdu.edu.cn/showproblem.php?pid=1542 Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6788    Accepted Submission(s):

fcbruce 1336

一文吃透 ABAP CDS SELECT:语法全景、关联与去重、可运行示例与实战心法

摘要: 本文深入解析ABAP中CDS视图的SELECT语法,重点介绍两种等价写法、关联与路径表达式优化、DISTINCT去重逻辑及WHERE/GROUP BY/HAVING/UNION等子句的应用。通过可运行的业务伙伴角色去重、关联路径查询及多角色筛选示例,演示如何将CDS特性转化为项目实践。强调关联复用性优于传统JOIN,并指出DISTINCT的权限边界与误用场景,帮助开发者从行式思维转向图式数据建模。(150字) 关键词: ABAP CDS、SELECT语法、路径表达式、DISTINCT去重、关联复用

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 403

HDU - 1542 Atlantis(区间修改,扫描线,离散化)

HDU - 1542 Atlantis 题目 在平面上给出 n 个矩形,求矩形并的面积。 首先用扫描线按矩形的水平边分段,如上图。在同一段的面积一起计算,即同一种颜色。

Stormjing的博客 255

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU-1542/POJ-1151 Atlantis(矩形并面积--线段树+离散化)

题目链接:\quadHDU - 1542 or POJ - 1151题目大意:\quad以对角线的形式给出nn个矩形,给出左下点(x1,y1)(x_1, y_1)和右上点(x2,y2)(x_2, y_2),double型。求nn个矩形的并面积。(多组)数据范围:1≤n≤1000≤x1<x2≤1000000≤y1<y2≤100000\quad 1 \leq n \leq 100 \quad 0 \le

XzzF1024的博客 828

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

hdu1542 Atlantis(矩形面积并+扫描线)

http://acm.hdu.edu.cn/showproblem.php?pid=1542 题意:给你n个矩形,求他们的周长面积并。 思路:看了两篇比较好的博客,推荐下第一个、第二个。求面积时要想用扫描线,首先要确定水平还是竖直方向。这里是从下往上扫描,由于横坐标较大所以对其离散化。离散化还是保存排序去重的步骤,重点是对这里扫描的理解。必须要注意的是,扫描线是可变的。提前用seg

Iguodala的博客 453

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu 1542 Atlantis&&hdu 1255 覆盖的面积(扫描线入门)

扫描线需要用到的知识点:线段树、离散化 (没了) 下面就进入扫描线入门题讲解 扫描线一般运用在图形上面,它和它的字面意思十分相似,就是一条线在整个图上扫来扫去,它一般被用来解决图形面积,周长等问题。 hdu 1542 Atlantis There are several ancient...

weixin_44003265的博客 324

hdu 1542 Atlantis(线段树 面积并+扫描线)

http://acm.hdu.edu.cn/showproblem.php?pid=1542 题意:给n个矩形的左下角和右上角的顶点坐标,求n个矩形的面积并。 思路: 首先离散化,因为矩形端点坐标非常大。如果从下向上扫描,离散横坐标,如果从右向左扫描,离散纵坐标。这里,离散横坐标,从下向上扫描。 离散时,先对横坐标排序, 去重,最后每个下标对应一个横坐标。再对离散后的横坐标建树。用结构体

1506

HDU 1542 Atlantis(线段树扫描线·面积并)

题意  给你一些矩形的左下和右上的坐标  求这些矩形的面积并 最基础的扫描线  理解了就是个水题了  先看一些图吧                                                   恩  看完了有什么感觉没有  那些红色的线就可以当作传说中的扫描线  就像从左到右扫描嘛  可以发现  矩形有竖直边的地方就有这些线  这些线把把拼在一起的矩形切

Deng's site \# 1142

【扫描线】HDU 1542 Atlantis

HDU 1542 Atlantis 题意:给出n个矩形,矩形间可能有重复的区域。问所有矩形覆盖的面积?【题目中说给的信息是矩形左上和右下的坐标信息(因为它的坐标面是y的正方向是向下的),无所谓,反过来就好】 思路:扫描线的模板题。 FEELING:目前写了两遍。第一遍当然自己写不下来。大致理解了之后开始回忆着敲,有很多bug。然后发现其实还是有不懂的地方。就是对于线段树的建树和pushup...

L_X_ 247

HDU 1542 Atlantis(离散化+扫描线(求并面积)+线段树)

题目点这里 贴个链接http://www.cnblogs.com/ka200812/archive/2011/11/13/2247064.html,扫描线启蒙; -----------------------------------------------------------------------------------------------------------------

Xgtao599的博客 658

hdu 1542 Atlantis (扫描线+离散化线段树求多矩形总面积)

题目链接:哆啦A梦传送门 题意:给n个矩形,求它们的总面积,覆盖的只算一次。每个矩形给出左下点和右上点。 参考博客1: 参考博客2 扫描线从下往上扫描,每次求出该扫描线的有效长度,再与两条线之间的高度相乘就是最后的面积。 线段树更新,遇到该边为矩形的下边就加进去,遇到该边为矩形的上边就减掉。 代码: #include<cstdio> #include<...

Jiandong 372

hdu 1542 (poj1151) Atlantis ( 线段树求矩形面积并)

离散化+扫描线+线段树。 虽然这题直接离散化也能过,但想要学习一下线段树求矩形并,就网搜各种线段树求矩形并的方法。其实做法还是跟离散化的做法差不多。 先介绍离散化+扫描线的做法(这种情况适应矩形数目不是很多的时候): 1,将矩形的四条边无限延长,则将平面区域分为了多个小矩形区域。我们要求的区域面积就是其中一些的小矩形的面积的和。(这一步只是理解,无实际操作) 2,分别将上述水平的划分线和竖直

Balloons2012的专栏 1516

hdu1542-Atlantis 线段树+扫描线+离散化 求面积并

Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13435    Accepted Submission(s): 5582 Problem Description There are severa

wangheng 416

HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)

传送门 •题意   给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标;   让你求这 n 个矩形并的面积;   其中$x \leq 10^{5} \ ,\ y \leq 10^{5}$; •题解   这类题的解决方法需要用到一个比较重要的算法--扫描线算法;   其实并不需要将扫描线算...

weixin_30267697的博客 211

扫描线算法学习-完全解析 HDU 1542 Atlantis

文章目录前言例题引入扫描线算法介绍及演示如何实现入边和出边步骤区间表示注意事项代码实现参考资料 前言 看了好久的扫描线,终于看懂了,想用自己的语言阐述一下,加深理解。也供各位读者学习。 注:学习本文之前首先得会线段树,离散化等操作,这里给出两篇blogblogblog​​供参考:程序设计之离散化,线段树入门。 例题引入 题目链接 HDU-1542 Atlantis 题目大意 给你nnn​​​个矩形,求它们的矩形面积并,即覆盖在平面上的面积为多少。 思考 针对求每个单独矩形的面积,实际上我们

pursuit的博客 1141
上一篇: POJ 2528 Mayor's posters (线段树+离散化)
下一篇: POJ 3667 Hotel (线段树求最长连续子序列)
WANSNIM
博客等级 码龄12年 27粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址