POJ-1177 Picture 矩形覆盖周长并
题目链接:http://poj.org/problem?id=1177
比矩形面积并麻烦点,需要更新竖边的条数(平行于x轴扫描)。。求横边的时候,保存上一个结果,加上当前长度与上一个结果差的绝对值就行了。。。
//STATUS:C++_AC_32MS_1416KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Seg{
int y,x1,x2;
int c;
Seg(){}
Seg(int a,int b,int c,int d):y(a),x1(b),x2(c),c(d){}
bool operator < (const Seg& a)const{
return y<a.y;
}
}seg[N];
bool lnod[N<<],rnod[N<<];
int len[N<<],cnt[N<<],cnt2[N<<];
int n,m; void pushup(int l,int r,int rt)
{
if(cnt[rt]){
lnod[rt]=rnod[rt]=true;
len[rt]=r-l+;
cnt2[rt]=;
}
else if(l==r)cnt2[rt]=lnod[rt]=rnod[rt]=len[rt]=;
else {
int ls=rt<<,rs=rt<<|;
lnod[rt]=lnod[ls],rnod[rt]=rnod[rs];
len[rt]=len[ls]+len[rs];
cnt2[rt]=cnt2[ls]+cnt2[rs];
if(rnod[ls] && lnod[rs])cnt2[rt]-=;
}
} void update(int a,int b,int c,int l,int r,int rt)
{
if(a<=l && r<=b){
cnt[rt]+=c;
pushup(l,r,rt);
return;
}
int mid=(l+r)>>;
if(a<=mid)update(a,b,c,lson);
if(b>mid)update(a,b,c,rson);
pushup(l,r,rt);
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,l,r,a,b,c,d,ans,last;
const int M=;
while(~scanf("%d",&n))
{
m=;
for(i=;i<n;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
a+=M,b+=M,c+=M,d+=M;
seg[m++]=Seg(b,a,c,);
seg[m++]=Seg(d,a,c,-);
}
sort(seg,seg+m);
mem(len,);mem(cnt,),mem(cnt2,);
mem(lnod,);mem(rnod,);
ans=last=;
for(i=;i<m-;i++){
update(seg[i].x1,seg[i].x2-,seg[i].c,,,);
ans+=cnt2[]*(seg[i+].y-seg[i].y);
ans+=abs(len[]-last);
last=len[];
}
update(seg[i].x1,seg[i].x2-,seg[i].c,,,); printf("%d\n",ans+abs(len[]-last));
}
return ;
}
POJ-1177 Picture 矩形覆盖周长并的更多相关文章
- POJ 1177 Picture(线段树周长并)
描述 A number of rectangular posters, photographs and other pictures of the same shape are pasted on ...
- HDU 1828 / POJ 1177 Picture --线段树求矩形周长并
题意:给n个矩形,求矩形周长并 解法:跟求矩形面积并差不多,不过线段树节点记录的为: len: 此区间线段长度 cover: 此区间是否被整个覆盖 lmark,rmark: 此区间左右端点是否被覆盖 ...
- poj 1177 Picture (线段树 扫描线 离散化 矩形周长并)
题目链接 题意:给出n个矩形,每个矩形给左下 和 右上的坐标,求围成的周长的长度. 分析: 首先感谢大神的博客,最近做题经常看大神的博客:http://www.cnblogs.com/kuangbin ...
- poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)
题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...
- 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 题目大意:若干个矩形,求这些矩形重叠形成的图形的轮廓周长. 解题思路:这里引用一下大牛的思路:kuangbin 总体思路: 1. ...
- POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)
题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...
- poj 1177 Picture(线段树周长并)
题目链接:http://poj.org/problem?id=1177 题意:给你n个矩形问你重叠后外边缘总共多长. 周长并与面积并很像只不过是处理的时候是 增加的周长=abs(上一次的线段的长度 ...
- N - Picture - poj 1177(扫描线求周长)
题意:求周长的,把矩形先进行融合后的周长,包括内周长 分析:刚看的时候感觉会跟棘手,让人无从下手,不过学过扫描线之后相信就很简单了吧(扫描线的模板- -),还是不说了,下面是一精确图,可以拿来调试数据 ...
随机推荐
- CDH安装Hadoop
一.安装CDH-manager 1.关闭selinux 修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可 2 ...
- python的生成器
1.生成器 >>> def func1(): ... yield 0 ... yield 1 ... >>> a=func1() >>> a.ne ...
- <a>作Form表单提</a>
1. Form表单<%using (Html.BeginForm("AddRoles", "RoleManage", FormMethod.Post, n ...
- MapReduce多表连接
多表关联 多表关联和单表关联类似,它也是通过对原始数据进行一定的处理,从其中挖掘出关心的信息.下面进入这个实例. 1 实例描述 输入是两个文件,一个代表工厂表,包含工厂名列和地址编号列:另一个代表地址 ...
- 【gitlab】版本管理工具
- CODEVS 3286 火柴排队
[题目描述 Description] 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度.现在将每盒中的火柴各自排成一列,同一列火柴的高度互不相同,两列火柴之间的距离定义为: ,其中 ai表示 ...
- DB天气app冲刺第五天
今天上了软工的一节课,感觉自己前几天的方向错了,而且基本是在耗时间,因为虽然一直在努力的看书 编代码,但效果不明显.所以今天要好好想一个新的方向重新来过. 明天送上计划.
- 《有限元分析基础教程》(曾攀)笔记一-二维杆单元有限元程序(基于Python)
曾攀老师的<有限元分析基础教程>第三章有二维杆单元的推导,并结合一个例题进行了解析解和基于Matlab的程序求解.但是我感觉书中的MATLAB代码有点罗嗦,而且一些实现方法也比较麻烦,比如 ...
- ExtJS4.2学习(14)基于表格的扩展插件(2)(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-26/184.html --------------- ...
- RandomAccessFile类的使用(随机读取java中的文件)
package coreJava; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; ...