POJ1151 Atlantis 扫描线算法】的更多相关文章

题目大意 给出几个矩形对角端点坐标,求这些矩形整体覆盖的面积. 扫描线算法 整个平面被每个矩形的水平边所在直线(以后简称“水平线”)分成了几个部分,而整体覆盖面积则为每相邻的两个水平线间夹的长度(以后简称“夹长”)以及水平线所对应的一个或几个矩形水平边(以后简称“水平线段”)在水平线中所占的长度之积的和.于是我们假设有一个扫描线从下往上扫.由排序得到夹长很容易,但是水平线段长就要用线段树了. 线段树 节点维护的是什么 水平线段在两个点[l,r]之间所占的长度CoverLen. l,r是doubl…
[POJ1151]Atlantis 试题描述 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.…
题目: Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23758   Accepted: 8834 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts…
Description 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…
Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16882   Accepted: 6435 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of…
题目链接:http://poj.org/problem?id=1151 扫描线+离散+线段树,线段树每个节点保存的是离散后节点右边的线段. //STATUS:C++_AC_16MS_208KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstream>…
有点难,扫描线易懂,离散化然后线段树处理有点不太好理解. 因为这里是一个区间,所有在线段树中更新时,必须是一个长度大于1的区间才是有效的,比如[l,l]这是一根线段,而不是区间了. AC代码 #include <stdio.h> #include <map> #include <vector> #include <algorithm> using namespace std; + ; struct Line{ double x, y1, y2; int fl…
http://poj.org/problem?id=1151 想学一下扫描线线段树,结果写了道水题. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<set> using namespace std; ; int n; ]; ]; ],c[maxn*]; ,tot1=; int main…
扫描线终于看懂了...咕咕了快三个月$qwq$ 对于所有的横线按纵坐标排序,矩阵靠下的线权值设为$1$,靠上的线权值设为$-1$,然后执行线段树区间加减,每次的贡献就是有效宽度乘上两次计算时的纵坐标之差. $cnt$数组记录每个位置被覆盖的次数,$sum$数组用来记区间总长度(即有效宽度),所以每一次把$sum[1]$乘上高就行了. 注意到每个$r$都减了$1$,原因是原先的坐标是点的坐标,而现在一个位置代表一个区间. #include<cstdio> #include<iostream…
题目:http://poj.org/problem?id=1151 经典的扫描线问题: 可以用线段树的每个点代表横向被矩形上下边分割开的每一格,这样将一个矩形的出现或消失化为线段树上的单点修改: 每个格子记录两个值:c(矩形存在情况),sum(对当前答案作出贡献的长度): 将y离散化作为建树的依据: 一开始没想到线段树上的点应该是横向的格子,写了个乱七八糟: #include<iostream> #include<cstdio> #include<cstring> #i…
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noip前的杂题训练,我也很无奈啊 做完了的扔最后,欢迎好题推荐 这么多题肯定是完不成了,能多做一道是一道吧 DP yyb真是强得不要不要的辣:http://www.cnblogs.com/cjyyb/category/1036536.html [ ] [SDOI2010]地精部落 https://www…
[POJ1151]Atlantis(线段树,扫描线) 题面 Vjudge 题解 学一学扫描线 其实很简单啦 这道题目要求的就是若干矩形的面积和 把扫描线平行于某个轴扫过去(我选的平行\(y\)轴扫) 这样只需要求出每次和\(x\)轴覆盖的长度 就可以两两相乘,求出面积 最后累计和就行啦 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cma…
题目链接: Atlantis Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others) Problem Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include ma…
入门看这边『线段树 Segment Tree』. 扫描线 扫描线是一种解决一类平面内统计问题的算法,通常会借助线段树来实现,我们通过一道例题来引入这个算法. Atlantis Description 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…
Atlantis poj1151 线段树扫描线 题意 题目给了n个矩形,每个矩形给了左下角和右上角的坐标,矩形可能会重叠,求的是矩形最后的面积. 题解思路 这个是我线段树扫描线的第一题,听了学长的讲解,仔细研读了学长的代码,也算初步入门. 这里我们竖着的扫描线,从左到右来进行扫描的. 线段树这里端点代表的是一个区间 这里的y范围比较大,所以咱们需要离散化. 代码实现 #include<cstdio> #include<cstring> #include<algorithm&g…
Description 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…
题目大意:给定 N 个矩形,求这些矩形的面积并. 题解:采用扫描线算法. 首先,按照矩形的横坐标排序,在纵坐标方向上维护一根扫描线被覆盖的长度,在这里采用线段树维护.统计答案时,从左到右扫描 2N 个 X 坐标,两个坐标之间的扫描线被覆盖的长度相等,因此直接长乘宽计入答案即可. 注意事项 由于坐标不是整数,因此采用离散化. 线段树动态开点即可. 跟以往线段树不同的地方在于,这里的线段树的区间修改并没有没有下传标记.原因可以总结为查询时只询问根节点的信息,没有必要下传标记. 代码如下 #inclu…
英文题面,我就只放个传送门了. Solution  题意是算矩形面积并,这是扫描线算法能解决的经典问题. 算法的大致思想是,把每一个矩形拆成上边和下边(以下称作扫描线),每条扫描线有四个参数l,r,h,v.l和r为它的左右端点的横坐标,h为扫描线的纵坐标,v下面再解释. 然后把扫描线按h从小到大排序,想一想,所有相邻扫描线之间的有效面积(即被矩形覆盖的面积)加起来是不是就是ans? 怎么求呢?我们从下往上处理,设当前处理到第i条扫描线,设第i条扫描线与第i+1条扫描线之间的有效面积为s,那么s=…
题意:给出n个矩形的左下角左边和右上角坐标,求这n个矩形的面积并 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 典型的扫描线算法的题目 什么是扫描线? 顾名思义,扫描线就是用一根平行于x轴或y轴的线,把所有矩形都扫过去,并在这个过程逐渐把这些矩形的面积并求出来,下图给了平行于y轴的线的扫描情形 那么这条扫描线是怎么实现的呢? 以下讲述扫描线平行于y轴的情形 先说说扫描线的移动问题 第一步,坐标离散化 第二步,开始扫描 这根线顺着离散化后的…
题目链接:http://poj.org/problem?id=1151 题目: 题意:求所有矩形的面积,重合部分只算一次. 思路:扫描线入门题,推荐几篇学扫描线的博客: 1.http://www.cnblogs.com/scau20110726/archive/2013/04/12/3016765.html 2.https://blog.csdn.net/qq_38786088/article/details/78633478 3.https://blog.csdn.net/lwt36/arti…
题意 给定\(n​\)个矩形\((x_1,y_1,x_2,y_2)​\),求这\(n​\)个矩形的面积并 题解 扫描线裸题,可以不用线段树维护,\(O(n^2)\)是允许的. #include <cstdio> #include <cstring> #include <algorithm> using std::sort; using std::unique; using std::lower_bound; const int N = 1e2 + 10; int n,…
n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=100000 这就要到扫描线了. 之前一直不会. 不好处理的地方在于:不知道区间被覆盖怎么计算.... 像sum区间和一样计算??sum>区间长度也不一定完全包含... 不管覆盖多少次,就只算一次??之后的减法怎么算?? 总之, 这篇题解打消了我的疑惑:ACM POJ1151 (HDU 1542) Atl…
Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21511   Accepted: 8110 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of…
平面上有若干个矩形,求矩形相互覆盖的面积.为方便起见,矩形的边均平行于坐标轴. 我们根据容斥原理,矩形相互覆盖的面积即为所有矩形的面积和减去所有矩形所覆盖的面积即可. 而现在问题是如何求得所有矩形所覆盖的面积.即 让我们人类去做,由于这是个由矩形拼接成的多边形,很难去直接求它的面积,求该图形的面积一个常规的方法就是割补法. 此处我们采用割,割成一个一个矩形出来. 这样就很方便地去求了. 计算机无法直观地看出图形,进而去求出长宽进而求出矩形面积. 那该如何让计算机来求? 我们看这些图形,一块一块的…
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description 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 u…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6116    Accepted Submission(s): 2677 Problem Description There are several ancient Greek texts that contain descriptions of the fabled i…
http://poj.org/problem?id=1151 经典矩形面积并吧.....很简单我就不说了... 有个很神的地方,我脑残没想到: 将线段变成点啊QAQ这样方便计算了啊 还有个很坑的地方,为毛每一次我精确地计算过空间可就是wa....一改大就ac...我无力了.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostrea…
Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11551    Accepted Submission(s): 4906 Problem Description There are several ancient Greek texts that contain descriptions of the fabled…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 参考网址:http://blog.csdn.net/sunmenggmail/article/details/7984589 Problem Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts…
一样的题:HDU 1542 Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18148   Accepted: 6902 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include map…