poj 1389 Area of Simple Polygons
2013-08-11 20:07
302 查看
链接:点击打开链接
没看题意,应该就给你多个矩形,让你求出总面积,覆盖多次的算一次。其实和hdu 覆盖的面积差不多,线段树+离散化+扫描线。poj 1151的代码改一下就过啦,这三道题基本就是一样的。
没看题意,应该就给你多个矩形,让你求出总面积,覆盖多次的算一次。其实和hdu 覆盖的面积差不多,线段树+离散化+扫描线。poj 1151的代码改一下就过啦,这三道题基本就是一样的。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; #define N 11000 struct node1{ int x,y1,y2; int flag; }a ; struct node2{ int down,up,x; int cover,child; }anode ; int y ,yd ; int m,n; int cmp(node1 a,node1 b){ return a.x<b.x; } void bulid(int l,int r,int n){ anode .down=yd[l]; anode .up=yd[r]; anode .child=1; anode .cover=0; if(l==r-1){ anode .child=0; return; } int mid=(l+r)>>1; bulid(l,mid,2*n); bulid(mid,r,2*n+1); } int update(int l,int r,int x,int flag,int n){ if(anode .up <= l || anode .down >= r) return 0; if(anode .child == 0) { if(anode .cover > 0) { int ans = (x-anode .x)*(anode .up-anode .down); anode .cover += flag; anode .x = x; return ans; } else { anode .cover += flag; anode .x = x; return 0; } } return update(l,r,x,flag,2*n)+update(l,r,x,flag,2*n+1); } int main(){ int i,j,t=1; int x1,y1,x2,y2,aera; while(1){ m=0; while(scanf("%d %d %d %d",&x1,&y1,&x2,&y2)){ if(x1==-1&&y1==-1&&x2==-1&&y2==-1){ if(m!=0) break; else{ t=0; break; } } m++; a[m].x=x1,a[m].y1=y1,a[m].y2=y2,a[m].flag=1; y[m]=y1; m++; a[m].x=x2,a[m].y1=y1,a[m].y2=y2,a[m].flag=-1; y[m]=y2; } if(!t) break; sort(y+1,y+1+m); sort(a+1,a+1+m,cmp); j=1; yd[1]=y[1]; for(i=2;i<=m;i++){ if(y[i]!=y[i-1]) yd[++j]=y[i]; } bulid(1,j,1); aera=0; for(i=1;i<=m;i++) aera+=update(a[i].y1,a[i].y2,a[i].x,a[i].flag,1); printf("%d\n",aera); } return 0; }
相关文章推荐
- 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
- POJ 1389 Area of Simple Polygons .
- POJ1389:Area of Simple Polygons——扫描线线段树题解+全套代码注释
- hdoj 1542 && poj 1151 Atlantis && poj 1389 Area of Simple Polygons 【线段树 + 离散化 + 扫描线】
- poj 1389 Area of Simple Polygons 线段树扫面线,和1151一样的嘛
- POJ1389[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