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轴的边,然后顺序处理 如果遇到矩形 ...
随机推荐
- 监控系统对比 Ganglia vs Open-falcon vs Prometheus vs Zabbix vs Nagios vs PandoraFMS
Zabbix vs Nagios vs PandoraFMS: an in depth comparison - Pandora FMS - The Monitoring Bloghttps://bl ...
- vmware can not be closed virtual machine is busy
VMware does not close when Windows Server 2003 ... |VMware Communities https://communities.vmware.co ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- 深浅copy详解
一. 前言 在python中,对象的赋值和深浅copy,是有差异的.最终得的值也不同,下面我们就通过几个例子,来看下它们之间的区别. 二. 赋值 list2 = ["jack",2 ...
- 获取打开页面时的当前时间(yyyy-MM-dd hh:mm:ss)
Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...
- 剑指Offer(9)
题目: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 解法: 要考虑到底数为0,指数为负数的情况,这道题主要考的是对边界值的思考. p ...
- Flutter的scope_model使用mixin语法报错
在pubspec.yaml同级目录下创建analysis_options.yaml文件,内容: # https://www.dartlang.org/guides/language/analysis- ...
- ASP.NET4.0所有网页指令
ASP.NET网页指令(Page Directive)就是在网页开头的标签声明: <% Page Language="C#" %> 而指令的作用在于指定网页和用户控件编 ...
- 集合之HashSet(含JDK1.8源码分析)
一.前言 我们已经分析了List接口下的ArrayList和LinkedList,以及Map接口下的HashMap.LinkedHashMap.TreeMap,接下来看的是Set接口下HashSet和 ...
- 如何在Mac系统安装MySQL
方法一: (1)使用brew install mysql (2)使用mysql -uroot连接时报错: Authentication plugin 'caching_sha2_password' c ...