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轴的边,然后顺序处理 如果遇到矩形 ...
随机推荐
- 【学习总结】Git学习-参考廖雪峰老师教程三-创建版本库
学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...
- 上传图片(photoClip)
首先我们需要引入4个js包(这4个包总共106.6KB) <script src="__STATIC__/hammer.min.js" ></script> ...
- 一条SQL语句执行得很慢的原因有哪些?(转)
一条 SQL 语句执行的很慢,那是每次执行都很慢呢?还是大多数情况下是正常的,偶尔出现很慢呢?所以我觉得,我们还得分以下两种情况来讨论. 1.大多数情况是正常的,只是偶尔会出现很慢的情况. 2.在数据 ...
- [转帖]dd命令详解
dd命令详解 https://czmmiao.iteye.com/blog/1748748 之前一直对linux的命令很恐惧 现在发现 其实不是那么复杂 要仔细学习就可以了 比如 dd = disk ...
- java学习之—合并两个数组并排序
/** * 合并两个数组并排序 * Create by Administrator * 2018/6/26 0026 * 下午 4:29 **/ public class MergeApp { pub ...
- 当应用程序不是以UserInteractive 模式运行时显示模式对话框或窗体
最近在做一个WCF程序的时候,WCF程序老是弹出一个错误“当应用程序不是以UserInteractive 模式运行时显示模式对话框或窗体是无效操作.请指定ServiceNotification或Def ...
- HashMap、HashTable、ConcurrentHashMap、HashSet区别 线程安全类
HashMap专题:HashMap的实现原理--链表散列 HashTable专题:Hashtable数据存储结构-遍历规则,Hash类型的复杂度为啥都是O(1)-源码分析 Hash,Tree数据结构时 ...
- git 提交的步骤
1. git init //初始化仓库 2. git add .(文件name) //添加文件到本地仓库 3. git commit -m "first commit" / ...
- react使用setstate注意的两点
1.this.state里的属性不修改,或是只修改一个,那么不修改的剩下的属性不会被变动. this.state={ name:"Aliece", age:19, msg:&quo ...
- CUDA开发
CUB库 https://nvlabs.github.io/cub/index.html