题目链接: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 矩形覆盖周长并的更多相关文章

  1. POJ 1177 Picture(线段树周长并)

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

  2. HDU 1828 / POJ 1177 Picture --线段树求矩形周长并

    题意:给n个矩形,求矩形周长并 解法:跟求矩形面积并差不多,不过线段树节点记录的为: len: 此区间线段长度 cover: 此区间是否被整个覆盖 lmark,rmark: 此区间左右端点是否被覆盖 ...

  3. poj 1177 Picture (线段树 扫描线 离散化 矩形周长并)

    题目链接 题意:给出n个矩形,每个矩形给左下 和 右上的坐标,求围成的周长的长度. 分析: 首先感谢大神的博客,最近做题经常看大神的博客:http://www.cnblogs.com/kuangbin ...

  4. poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)

    题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...

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

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

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

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

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

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

  8. poj 1177 Picture(线段树周长并)

    题目链接:http://poj.org/problem?id=1177 题意:给你n个矩形问你重叠后外边缘总共多长. 周长并与面积并很像只不过是处理的时候是   增加的周长=abs(上一次的线段的长度 ...

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

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

随机推荐

  1. 找工作ing

    找工作已经一个月多了,这一个月跑来跑去,挺累的,倒也不是身体有多累,关键是心累!作为一名控制工程专业的研究生,想找一份软件开发类的工作,没想到这么难!在起初的时候,觉得自己C++和JAVA都会,找哪个 ...

  2. *[topcoder]LittleElephantAndString

    http://community.topcoder.com/stat?c=problem_statement&pm=12854&rd=15709 这道题DIV1 250的,还有点意思. ...

  3. 9. MonoBehaviour.StartCoroutine 开始协同程序

    function StartCoroutine (routine : IEnumerator) : Coroutine 描述:开始协同程序. 一个协同程序在执行过程中,可以在任意位置使用yield语句 ...

  4. MSSQL版本

    (1)661是sql2008 R2的版本号     Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86)   Apr  2 201 ...

  5. 关于捕获键盘信息的processDialogkey方法

    在一些控件里的keydown方法,没有办法捕获所有的按键消息 比如自己写一个窗体控件库,继承了UserControl 但是没有办法捕获一些键,比如方向键等 所以必须重载 processDialogke ...

  6. Android开发之bindService()侦听service内部状态

    在Android开发之bindService()通信的基础上,实现bindService()方法侦听service内部状态. 实现侦听service内部状态,使用的是回调机制 1.首先实现一个接口 p ...

  7. Java 异常类层次结构

    在Java中,异常分为受检查的异常,与运行时异常. 两者都在异常类层次结构中. 下面的图展示了Java异常类的继承关系. 图1 粉红色的是受检查的异常(checked exceptions),其必须被 ...

  8. 结构体dtype_t

    /* SQL data type struct */ typedef struct dtype_struct dtype_t; struct dtype_struct{ unsigned mtype: ...

  9. 6个可以隐藏运行bat,浏览器等程序的方法

    在电脑启动时或者设置时间时运行指定的程序很容易实现.但是有时候还需要运行时不显示主界面,隐藏到后台运行.比如:开机时一段Bat批处理执行删除默认共享; 开机自动运行浏览器隐藏到后代打开指定网页等,希望 ...

  10. openlayer调用geoserver发布的地图实现地图的基本功能

    转自:http://starting.iteye.com/blog/1039809 主要实现的功能有放大,缩小,获取地图大小,平移,线路测量,面积测量,拉宽功能,显示标注,移除标注,画多边形获取经纬度 ...