扫描线求周长,可以看成两条线,一条扫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 (扫描线)的更多相关文章

  1. N - Picture - poj 1177(扫描线求周长)

    题意:求周长的,把矩形先进行融合后的周长,包括内周长 分析:刚看的时候感觉会跟棘手,让人无从下手,不过学过扫描线之后相信就很简单了吧(扫描线的模板- -),还是不说了,下面是一精确图,可以拿来调试数据 ...

  2. Picture POJ - 1177(扫描线求面积并)

    题意:求矩形并的面积.. 解析: 扫描线第一道题....自下而上扫描的... 如果不懂什么是扫描线戳我 #include <iostream> #include <cstdio> ...

  3. 求矩形的周长(线段树+扫描线) Picture POJ - 1177

    题目链接:https://cn.vjudge.net/problem/POJ-1177 题目大意:求矩形外部的周长 具体思路:借用一下bin巨的一张图片. 我们按照y周从下往上的扫描线进行扫描,第一下 ...

  4. Picture POJ - 1177 (线段树-扫描线)

    A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wa ...

  5. Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长

    参考  https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include ...

  6. POJ - 1177 线段树

    POJ - 1177 扫描线 这道题也算是一道扫描线的经典题目了. 只不过这道题是算周长,非常有意思的一道题.我们已经知道了,一般求面积并,是如何求的,现在我们要把扫描线进行改造一下,使得能算周长. ...

  7. POJ 1177 Picture(线段树:扫描线求轮廓周长)

    题目链接:http://poj.org/problem?id=1177 题目大意:若干个矩形,求这些矩形重叠形成的图形的轮廓周长. 解题思路:这里引用一下大牛的思路:kuangbin 总体思路: 1. ...

  8. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

  9. POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)

    题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...

随机推荐

  1. swagger 指定字段不显示到文档里

    Swagger UI 隐藏指定接口类或方法 - 宁静致远 - CSDN博客https://blog.csdn.net/lqh4188/article/details/53538201 swagger ...

  2. window端编码到Linux允许脚本 笔记

    昨天升级一个服务,发现没有现成的启动脚本.就随手写了一个,一运行发现不行.竟然报错说找不到文件,No such file or directory [nohup: cannot run command ...

  3. java编程规范(持续更新)

    1:非空判断 错误例子: if(user.getUserName().equals("hollis")){ } 这段代码极有可能在实际运行的时候跑出NullPointerExcep ...

  4. springmvc配置文件的主要内容

    springmvc配置文件的主要内容:

  5. 转 freemarker macro(宏)的使用

    有人说用freemarker,但没有用到它的宏(macro),就=没有真正用过freemarker.说的就是宏是freemarker的一大特色. 宏的定义可以查看相关的文档,里面介绍得很清楚,下面来看 ...

  6. 1.docker 数据卷的备份和恢复(非大数据量)

    在生产环境中使用 Docker,很多时候需要对数据进行持久化,或者进行容器间的数据共享. 容器中的管理数据主要有两种方式: 数据卷 (Data Volumes): 容器内数据直接映射到本地主机环境: ...

  7. codeforces158C

    Cd and pwd commands CodeForces - 158C Vasya is writing an operating system shell, and it should have ...

  8. HTML5获取地理位置信息

    <!DOCTYPE html> <html> <head> <title>Location</title> <meta charset ...

  9. BZOJ1398Vijos1382寻找主人 Necklace——最小表示法

    题目描述 给定两个项链的表示,判断他们是否可能是一条项链. 输入 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的). 输出 如果两条项链不可能同构,那么输出 ...

  10. Codeforces Round #437 Div. 1

    A:显然构造一组只包含1和2面值的数据即可. #include<iostream> #include<cstdio> #include<cmath> #includ ...