Picture POJ - 1177 (扫描线)
扫描线求周长,可以看成两条线,一条扫x轴,一条扫y轴,然后这两天线扫过去的 周长加起来,就是周长了
#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 first fi
#define second se
#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 {
int l, r, h, f;
bool operator < (Node a) const {
return h < a.h;
}
};
Node node[][maxn];
int sum[maxn << ];
int cnt[maxn << ];
int a[][maxn]; void init() {
memset(node, , sizeof node);
memset(a, , sizeof a);
} void pushup(int left, int right, int flag, int root) {
if(cnt[root]) {
sum[root] = a[flag][right+] - a[flag][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 flag, int val, int root) {
if(prel <= left && right <= prer) {
cnt[root] += val;
pushup(left, right, flag, root);
return ;
}
int mid = (left + right) >> ;
if(prel <= mid) update(left, mid, prel, prer, flag, val, root << );
if(prer > mid) update(mid+, right, prel, prer, flag, val, root << | );
pushup(left, right, flag, root);
} int main() {
while(~scanf("%d", &n)) {
init();
for(int i=; i<=n; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
node[][i].l = x1, node[][i+n].l = x1;
node[][i].r = x2, node[][i+n].r = x2;
node[][i].h = y1, node[][i+n].h = y2;
node[][i].f = , node[][i+n].f = -;
a[][i] = x1, a[][i+n] = x2;
node[][i].l = y1, node[][i+n].l = y1;
node[][i].r = y2, node[][i+n].r = y2;
node[][i].h = x1, node[][i+n].h = x2;
node[][i].f = , node[][i+n].f = -;
a[][i] = y1, a[][i+n] = y2;
}
n <<= ;
sort(node[]+, node[]++n);
sort(node[]+, node[]++n);
sort(a[]+, a[]+n+);
sort(a[]+, a[]+n+);
int cnt1 = unique(a[]+, a[]++n) - (a[]+);
int cnt2 = unique(a[]+, a[]++n) - (a[]+);
int ans = ;
int last = ;
memset(sum, , sizeof sum);
memset(cnt, , sizeof cnt);
for(int i=; i<=n; i++) {
int l = lower_bound(a[]+, a[]+cnt1+, node[][i].l) - a[];
int r = lower_bound(a[]+, a[]+cnt1+, node[][i].r) - a[];
update(, cnt1, l, r-, , node[][i].f, );
ans += abs(sum[] - last);
last = sum[];
}
last = ;
memset(sum, , sizeof sum);
memset(cnt, , sizeof cnt);
for(int i=; i<=n; i++) {
int l = lower_bound(a[]+, a[]+cnt2+, node[][i].l) - a[];
int r = lower_bound(a[]+, a[]+cnt2+, node[][i].r) - a[];
update(, cnt2, l, r-, , node[][i].f, );
ans += abs(sum[] - last);
last = sum[];
}
printf("%d\n", ans);
}
return ;
}
Picture POJ - 1177 (扫描线)的更多相关文章
- N - Picture - poj 1177(扫描线求周长)
题意:求周长的,把矩形先进行融合后的周长,包括内周长 分析:刚看的时候感觉会跟棘手,让人无从下手,不过学过扫描线之后相信就很简单了吧(扫描线的模板- -),还是不说了,下面是一精确图,可以拿来调试数据 ...
- Picture POJ - 1177(扫描线求面积并)
题意:求矩形并的面积.. 解析: 扫描线第一道题....自下而上扫描的... 如果不懂什么是扫描线戳我 #include <iostream> #include <cstdio> ...
- 求矩形的周长(线段树+扫描线) Picture POJ - 1177
题目链接:https://cn.vjudge.net/problem/POJ-1177 题目大意:求矩形外部的周长 具体思路:借用一下bin巨的一张图片. 我们按照y周从下往上的扫描线进行扫描,第一下 ...
- Picture POJ - 1177 (线段树-扫描线)
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wa ...
- Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长
参考 https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include ...
- POJ - 1177 线段树
POJ - 1177 扫描线 这道题也算是一道扫描线的经典题目了. 只不过这道题是算周长,非常有意思的一道题.我们已经知道了,一般求面积并,是如何求的,现在我们要把扫描线进行改造一下,使得能算周长. ...
- POJ 1177 Picture(线段树:扫描线求轮廓周长)
题目链接:http://poj.org/problem?id=1177 题目大意:若干个矩形,求这些矩形重叠形成的图形的轮廓周长. 解题思路:这里引用一下大牛的思路:kuangbin 总体思路: 1. ...
- HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)
做这道题之前,建议先做POJ 1151 Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...
- POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)
题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...
随机推荐
- <c:forEach varStatus="status">中 varStatus的作用
varStatus是<c:forEach>jstl循环标签的一个属性,varStatus属性. varStatus=“status”事实上定义了一个status名的对象作为varStatu ...
- spring核心思想:IOC(控制反转)和DI(依赖注入)
Spring有三大核心思想,分别是控制反转(IOC,Inversion Of Controller),依赖注入(DI,Dependency Injection)和面向切面编程(AOP,Aspect O ...
- Laravel渴求式加载(比较容易理解理解load与with关系)
渴求式加载 当以属性方式访问 Eloquent关联关系的时候,关联关系数据是「懒惰式加载」的,这意味着关联关系数据直到第一次访问的时候才被加载.不过,Eloquent 还可以在查询父级模型的同时「渴求 ...
- Hbase存储模式
以key.value的结构存储数据; (table,rowkey,family,colum,timestamp)构成数据的key,value存储数据
- PLA-1
PLA(Principal Component Analysis)主成分分析: 思路1:坐标旋转 1.数据分布以及投影: 2.特征值以及特征向量 思路2: 未完待续...
- java 调用 wsdl形式的webservice 示例
import java.rmi.RemoteException; import javax.xml.rpc.ParameterMode; import javax.xml.rpc.ServiceExc ...
- mybatis generator的maven插件,找不到properties的配置文件错误的解决
第一次运行的时候,maven插件是正确运行了的 但后面对 maven 的 build节点做了一点修改,就开始报错,找不到 properties标签指定的的数据库连接配置文件了 修改部分如下: 这个操作 ...
- Lodop的JS模版代码、文档式模版 生成加载赋值博文索引
Lodop获取全部JS代码,传统JS模版的生成.LODOP设置打印设计返回JS代码是变量 LodopJS代码模版的加载和赋值 Lodop生成文档式模版 LodopJS文档式模版的加载和赋值 由于加载J ...
- Windows 10 安装PHP Manager 失败的解决办法
首先安装.NET 2.0和.NET 3.5, 在 控制面板----程序----启用或关闭Windows功能 里面 然后修改注册表:HKLM/System/CCS/Services/W3SVC/P ...
- 比特币中的Base58 编码
base58和base64一样是一种二进制转可视字符串的算法,主要用来转换大整数值.区别是,转换出来的字符串,去除了几个看起来会产生歧义的字符,如 0 (零), O (大写字母O), I (大写的字母 ...