POJ 1389 Area of Simple Polygons | 扫描线
2017-11-20 18:54
232 查看
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #define N 1010 5 #define LEN 60010 6 using namespace std; 7 struct Edge 8 { 9 int l,r,h,f; 10 bool operator < (const Edge &a) const 11 { 12 if (h==a.h) return f<a.f; 13 return h<a.h; 14 } 15 }edge[N*2]; 16 int cnt,s[4*LEN],cover[4*LEN],mx;
//cover[i]表示节点i代表区间被覆盖的次数(可以重复覆盖)
//s[i]表示节点i代表区间被覆盖长度(不可重复) 17 long long ans; 18 void insert(int i,int l,int r,int x,int y,int k) 19 { 20 if (y<l || x>r) return; 21 if (x<=l && y>=r) 22 { 23 cover[i]+=k; 24 if (cover[i]>0) s[i]=r-l+1;//当cover大于0,区间一定被全覆盖 25 else if (l==r) s[i]=0; 26 else s[i]=s[i*2]+s[i*2+1]; 27 return; 28 } 29 int mid=(l+r)>>1; 30 insert(i*2,l,mid,x,y,k); 31 insert(i*2+1,mid+1,r,x,y,k); 32 if (cover[i]==0) s[i]=s[2*i]+s[2*i+1];//cover等于0就从左儿子和右儿子更新 33 return; 34 } 35 Edge make(int a,int b,int c,int d) 36 { 37 Edge ret; 38 ret.l=a,ret.r=b,ret.h=c,ret.f=d; 39 return ret; 40 } 41 int main() 42 { 43 int a,b,c,d; 44 while (1) 45 { 46 cnt=ans=mx=0; 47 while (1) 48 { 49 scanf("%d%d%d%d",&a,&b,&c,&d); 50 mx=max(mx,c); 51 if (a==-1 && b==-1 && c==-1 && b==-1) break; 52 edge[++cnt]=make(a,c,b,1); 53 edge[++cnt]=make(a,c,d,-1); 54 } 55 if (cnt==0) break; 56 memset(cover,0,sizeof(cover)); 57 memset(s,0,sizeof(s)); 58 sort(edge+1,edge+1+cnt); 59 insert(1,0,mx,edge[1].l+1,edge[1].r,edge[1].f); 60 for (int i=2;i<=cnt;i++) 61 ans+=s[1]*(edge[i].h-edge[i-1].h),insert(1,0,mx,edge[i].l+1,edge[i].r,edge[i].f); 62 printf("%lld\n",ans); 63 } 64 return 0; 65 }
相关文章推荐
- hdoj 1542 && poj 1151 Atlantis && poj 1389 Area of Simple Polygons 【线段树 + 离散化 + 扫描线】
- POJ 1389 Area of Simple Polygons 线段树 扫描线
- POJ 1389 Area of Simple Polygons(线段树+扫描面积)
- poj_1389 Area of Simple Polygons 线段树+扫描线
- POJ 1389 Area of Simple Polygons .
- POJ1389[Area of Simple Polygons]
- POJ1389:Area of Simple Polygons——扫描线线段树题解+全套代码注释
- poj 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons 线段树求矩形面积
- POJ 1389 Area of Simple Polygons(线段树+扫描线求矩形面积并)
- [POJ1389 Area of Simple Polygons]
- poj 1389 Area of Simple Polygons 线段树扫面线,和1151一样的嘛
- POJ 1389 Area of Simple Polygons (离散化求矩形面积并)
- 【POJ 1389】Area of Simple Polygons(线段树+扫描线,矩形并面积)
- POJ 1389 Area of Simple Polygons 笔记
- [poj] 1389 Area of Simple Polygons
- 【POJ】1389 Area of Simple Polygons
- poj 1389 Area of Simple Polygons(线段树+扫描线)
- [POJ1389]Area of Simple Polygons(扫描线+线段树)
- POJ-1389-Area of Simple Polygons