标签:blog .com simple mes pac ace opera col print
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; 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; 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]; 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 }
POJ 1389 Area of Simple Polygons | 扫描线
标签:blog .com simple mes pac ace opera col print
原文地址:http://www.cnblogs.com/mrsheep/p/7867751.html