题目链接 题意 给出n个矩形,求面积并. 思路 使用扫描线,我这里离散化y轴,按照x坐标从左往右扫过去.离散化后的y轴可以用线段树维护整个y上面的线段总长度,当碰到扫描线的时候,就可以统计面积.这里要注意线段树上结点维护的是线段的信息,而不是点的信息. 参考资料 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int INF =…
题目链接题意:给定n个矩形,求面积并,分别给矩形左上角的坐标和右上角的坐标. 分析: 映射到y轴,并且记录下每个的y坐标,并对y坐标进行离散. 然后按照x从左向右扫描. #include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <cstdlib> #include <algorithm> #define LL __int64…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 分析:离散化+扫描线+线段树 #pragma comment(linker,"/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #in…
题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> #include <algorithm> #define MAXN 110 #define LL ((rt<<1)+1) #define RR ((rt<<1)+2) using namespace std; int n; struct segment{ double l…
一.题面 POJ3470 二.分析 POJ感觉是真的老了. 这题需要一些预备知识:扫描线,离散化,线段树.线段树是解题的关键,因为这里充分利用了线段树区间修改的高效性,再加上一个单点查询. 为什么需要离散化? 坐标太分散了,据说可以到 long long,但是就这么多个点,所以离散化一下,方便处理. 为什么用扫描线算法? 用扫描线,可以方便的求出一个bird到wall的距离,因为是顺着一个方向扫的(这题需要从四个方向扫),所以保证了准确性和高效性. 为什么用线段树? 用线段树非常明显,因为墙有这…
Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the window with some posters to prevent the glare outside. All things that Ted can find are rectangle posters. However, Ted is such a picky guy that in ev…
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​\)个矩形\((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,…
Problem - 4419 题意不难,红绿蓝三种颜色覆盖在平面上,不同颜色的区域相交会产生新的颜色,求每一种颜色的面积大小. 比较明显,这题要从矩形面积并的方向出发.如果做过矩形面积并的题,用线段树做的,这题就只差一个把每个区域计算单独出来的思路了. 这里不详细介绍扫描线,只是说一下针对这题的做法.其实网上有好多版本,都是直接单独计算答案的.然而,我稍微绕了个小弯,我觉得我这种处理方法也是比较容易想到以及实现的.如果我们用7棵线段树计算R.G.B.R||G.R||B.B||G.R||G||B这…
题目链接 题意 给出n个矩形,求周长并. 思路 学了区间并,比较容易想到周长并. 我是对x方向和y方向分别做两次扫描线.应该记录一个pre变量,记录上一次扫描的时候的长度,对于每次遇到扫描线统计答案的时候,使用当前的 tree[1] 去与 pre 做相减,因为这一次如果边长增加了或者减少了,那么一定和之前的值有差值,其中的差值就是这次的变化量. 但是这份代码交G++会WA,C++就A了.而且排序的时候如果权值相同,应该让状态为1(开始)的扫描线排在状态为-1(结束)的扫描线前面,因为重合的话,那…