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轴的边,然后顺序处理 如果遇到矩形 ...
随机推荐
- html,css学习实践总结
网页的布局方式 1.什么是网页的布局方式? 网页的布局方式其实就是指浏览器是如何对网页中的元素进行排版的 1.标准流(文档流/普通流)排版方式 1.1其实浏览器默认的排版方式就是标准流的排版方式 1. ...
- JMeter压测分布式部署
监控JMeter压力机的性能
- [转帖]前端-chromeF12 谷歌开发者工具详解 Network篇
前端-chromeF12 谷歌开发者工具详解 Network篇 https://blog.csdn.net/qq_39892932/article/details/82493922 blog 也是原作 ...
- Oracle字符函数length substr concat实例
--字符函数 --伪表dual --(1)求字符串长度 select length('123.456/-*') from dual --(2)截取函数求字符串的子串 ,) from dual --(3 ...
- v-router几种定义方式
第一种 const router = new VueRouter({ routes: [{ path: '/newSongs', component: require('../views/NewSon ...
- Docker实现运行tomcat并部署项目war包,并实现挂载目录
之前写的有点乱,现在再来整理一下docker的简单部署运行 借鉴博客:https://blog.csdn.net/qq_32351227/article/details/78673591 一.dock ...
- 在linux和本地系统之间进行数据传输的简单方法--lrzsz
lrzsz是一款在linux里可代替ftp上传和下载的程序. >>提君博客原创 http://www.cnblogs.com/tijun/ << 提君博客原创 安装和使用非 ...
- rpm和yum
RMP(红帽软件包管理器) RPM有点像Windows系统中的控制面板,会建立统一的数据库文件,详细记录软件信息并能够自动分析依赖关系. YUM(软件仓库)
- Socket和ObjectOutputStream问题
用到Socket序列化对象网络传输时ObjectOutputStream一直刷新连接 用户代码 package com.jachs.ladflower.ladflower; import java.n ...
- Sqoop 使用详解(内含对官方文档的解析)
Sqoop 是 Cloudera 公司创造的一个数据同步工具,现在已经完全开源了. 目前已经是 hadoop 生态环境中数据迁移的首选,另外还有 ali 开发的 DataX 属于同类型工具,由于社区的 ...