标签:style blog http color os io for art
Atlantis http://poj.org/problem?id=1151 http://acm.hdu.edu.cn/showproblem.php?pid=1542
1 #include<cstdio> 2 #include<algorithm> 3 #include<map> 4 #define lrrt int L,int R,int rt 5 #define iall 1,n,1 6 #define imid int mid=(L+R)>>1 7 #define lson L,mid,rt<<1 8 #define rson mid+1,R,rt<<1|1 9 using namespace std; 10 const int M=210; 11 struct line{ 12 double left,right,high; 13 int flag; 14 friend bool operator <(line a,line b){ 15 return a.high<b.high; 16 } 17 }l[M]; 18 double x[M]; 19 struct T{ 20 int cover; 21 double len; 22 }tree[M<<2]; 23 void build(lrrt){ 24 tree[rt].cover=0; 25 tree[rt].len=0; 26 if(L==R) return ; 27 imid; 28 build(lson); 29 build(rson); 30 } 31 void pushup(lrrt){ 32 if(tree[rt].cover) tree[rt].len=x[R-1]-x[L-2]; 33 else if(L==R) tree[rt].len=0; 34 else tree[rt].len=tree[rt<<1].len+tree[rt<<1|1].len; 35 } 36 void update(int x,int y,int val,lrrt){ 37 if(x<=L&&R<=y){ 38 tree[rt].cover+=val; 39 pushup(L,R,rt); 40 return ; 41 } 42 imid; 43 if(mid>=x) update(x,y,val,lson); 44 if(mid<y) update(x,y,val,rson); 45 pushup(L,R,rt); 46 } 47 map<double,int> toid; 48 int main(){ 49 int n,cas=1; 50 while(~scanf("%d",&n),n){ 51 int lx=0; 52 int len=0; 53 while(n--){ 54 double x1,y1,x2,y2; 55 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 56 x[lx++]=x1; 57 x[lx++]=x2; 58 l[len].left=x1; 59 l[len].right=x2; 60 l[len].high=y1; 61 l[len].flag=-1; 62 len++; 63 l[len].left=x1; 64 l[len].right=x2; 65 l[len].high=y2; 66 l[len].flag=1; 67 len++; 68 } 69 sort(x,x+lx); 70 sort(l,l+len); 71 n=unique(x,x+lx)-x; 72 build(iall); 73 toid.clear(); 74 for(int i=0;i<n;i++){ 75 toid[x[i]]=i+1; 76 } 77 double ans=0; 78 for(int i=0;i<len-1;i++){ 79 int s=toid[l[i].left]; 80 int e=toid[l[i].right]; 81 update(s+1,e,l[i].flag,iall); 82 ans+=(l[i+1].high-l[i].high)*tree[1].len; 83 } 84 printf("Test case #%d\nTotal explored area: %.2f\n\n",cas++,ans); 85 } 86 return 0; 87 }
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/gaolzzxin/p/3880239.html