POJ Area of Simple Polygons 扫描线】的更多相关文章

这个题lba等神犇说可以不用离散化,但是我就是要用. 题干: Description There are N, <= N <= , rectangles -D xy-plane. The four sides of a rectangle are horizontal or vertical line segments. Rectangles are defined by their lower-left and upper-right corner points. Each corner p…
---恢复内容开始--- LINK 题意:同POJ1151 思路: /** @Date : 2017-07-19 13:24:45 * @FileName: POJ 1389 线段树+扫描线+面积并 同1151.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <stdio.h> #incl…
请戳此处 #include<cstdio> #include<algorithm> #include<cstring> #define N 1010 #define LEN 60010 using namespace std; struct Edge { int l,r,h,f; bool operator < (const Edge &a) const { if (h==a.h) return f<a.f; return h<a.h; } }…
http://poj.org/problem?id=1389 题面描述在二维xy平面中有N,1 <= N <= 1,000个矩形.矩形的四边是水平或垂直线段.矩形由左下角和右上角的点定义.每个角点都是一对两个非负整数,范围从0到50,000,表示其x和y坐标. 求出所有矩形的面积(重叠部分只算一次) 示例:考虑以下三个矩形: 矩形1:<(0,0)(4,4)>, 矩形2:<(1,1)(5,2)>, 矩形3:<(1,1)(2,5)>. 所有由这些矩形构造的简单多…
离散化后,[1,10]=[1,3]+[6,10]就丢了[4,5]这一段了. 因为更新[3,6]时,它只更新到[3,3],[6,6]. 要么在相差大于1的两点间加入一个值,要么就让左右端点为l,r的线段树节点表示到x[l]到x[r+1]的区间. 这样tree[l,r]=tree[l,m]+tree[m+1,r]=[x[l],x[m+1]]+[x[m+1],x[r+1]] #include<iostream> #include<algorithm> #include<cstdio…
原题 线段树+扫描线 对于这样一个不规则图形,我们要求他的面积有两种方法,割和补. 补显然不行,因为补完你需要求补上去的内部分不规则图形面积-- 那么怎么割呢? 像这样: 我们就转化成了无数个矩形的和.要想求这些矩形的面积,也就是底成高.因为我们并不懂什么二维线段树,所以我们就用"扫描线"(从左到右的更新计算). 不妨把y轴当做一个线段树,然后维护哪些位置被覆盖了,直到下一条更新,所增加的面积就是被覆盖位置(高)和这两个距离的差(底)的乘积. Eg: 我们第一次更新建了第一条边的树,第…
poj1389:http://poj.org/problem?id=1389 题意:求矩形面积的并题解:扫描线加线段树 同poj1389 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ; int num; struct Node{ int l; int r; int tp; int y; bool operator…
POJ1389 给定n个整数点矩形,求面积并. 显然ans必然是整数. 记录若干个事件,每个矩形的左边的竖边记为开始,右边的竖边记为结束. 进行坐标离散化后用线段树维护每个竖的区间, 就可以快速积分了. #include<stdio.h> #include<stdlib.h> #include<cstring> #include<math.h> #include<algorithm> #include<vector> using na…
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大坑. 代码总览 #include <cstdio> #include <cstring> #include <algorithm> #define nmax 200000 using namespace std; struct Tree{ int l,r; long lon…
POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> #include<map> usi…