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(扫描线求周长)
题意:求周长的,把矩形先进行融合后的周长,包括内周长 分析:刚看的时候感觉会跟棘手,让人无从下手,不过学过扫描线之后相信就很简单了吧(扫描线的模板- -),还是不说了,下面是一精确图,可以拿来调试数据 ...
随机推荐
- chrome常用插件
1. ModHeader 功能:修改请求头部信息 安装地址:https://chrome.google.com/webstore/detail/idgpnmonknjnojddfkpgkljpfnnf ...
- hdu 1540 Tunnel Warfare (区间线段树(模板))
http://acm.hdu.edu.cn/showproblem.php?pid=1540 Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) ...
- selenium各种场景下的启动Firefox
开始学习selenium时为了启动Firefox可谓费尽周折,在大神的帮助下才堪堪搞定,走出了selenium的第一步:jdk1.8 + selenium_2.46 + Firefox国际版40.0. ...
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...
- android gridview按钮边框和定制点击颜色
<?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="ht ...
- Java集合类之HashMap
package com.test; import java.util.*; public class Demo7_3 { public static void main(String[] args) ...
- ANDROID_MARS学习笔记_S02_001_Spinner
1.strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> < ...
- Android imageview显示圆形图片
需要ImageView显示圆形图片做法如下 public static Bitmap toRoundCorner(Bitmap bitmap, float ratio) { System.out.pr ...
- Ember.js demo7
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1 ...
- Hibernate一级缓存、二级缓存
缓存就是把以前从数据库中查询出来和使用过的对象保存在内存中,准确说就是一个数据结构中,这个数据结构通常是或类似HashMap,当以后要使用某个对象时,先查询缓存中是否有这个对象,如果有则使用缓存中的对 ...