标签:rtu ace starting mono weight break push std single
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12059 Accepted Submission(s): 5083
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<map> 5 #include<cstdlib> 6 #include<vector> 7 #include<set> 8 #include<queue> 9 #include<cstring> 10 #include<string.h> 11 #include<algorithm> 12 #define INF 0x3f3f3f3f 13 typedef long long ll; 14 typedef unsigned long long LL; 15 using namespace std; 16 const int N=1000+100; 17 double x[2*N]; 18 struct Edge{ 19 double l,r; 20 double h; 21 int flag; 22 }edge[2*N]; 23 struct node{ 24 int l,r; 25 int s; 26 double len; 27 }tree[N*8]; 28 bool cmp(Edge x,Edge y){ 29 return x.h<y.h; 30 } 31 void pushup(int pos){ 32 if(tree[pos].s)tree[pos].len=x[tree[pos].r+1]-x[tree[pos].l]; 33 else if(tree[pos].l==tree[pos].r)tree[pos].len=0; 34 else{ 35 tree[pos].len=tree[pos<<1].len+tree[pos<<1|1].len; 36 } 37 } 38 void build(int l,int r,int pos){ 39 tree[pos].l=l;tree[pos].r=r; 40 tree[pos].s=0;tree[pos].len=0; 41 if(tree[pos].l==tree[pos].r)return; 42 int mid=(tree[pos].l+tree[pos].r)>>1; 43 build(l,mid,pos<<1); 44 build(mid+1,r,pos<<1|1); 45 } 46 void update(int l,int r,int pos,int xx){ 47 if(tree[pos].l==l&&tree[pos].r==r){ 48 tree[pos].s=tree[pos].s+xx; 49 pushup(pos); 50 return; 51 } 52 int mid=(tree[pos].l+tree[pos].r)>>1; 53 if(r<=mid)update(l,r,pos<<1,xx); 54 else if(l>mid)update(l,r,pos<<1|1,xx); 55 else{ 56 update(l,mid,pos<<1,xx); 57 update(mid+1,r,pos<<1|1,xx); 58 } 59 pushup(pos); 60 } 61 int main(){ 62 int n; 63 int tt=0; 64 while(scanf("%d",&n)!=EOF){ 65 tt++; 66 if(n==0)break; 67 int t=0; 68 for(int i=0;i<n;i++){ 69 double x1,x2,y1,y2; 70 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 71 Edge &t1=edge[t];Edge &t2=edge[t+1]; 72 t1.l=t2.l=x1;t1.r=t2.r=x2; 73 t1.h=y1;t2.h=y2; 74 t1.flag=1;t2.flag=-1; 75 x[t]=x1;x[t+1]=x2; 76 t=t+2; 77 } 78 sort(edge,t+edge,cmp); 79 sort(x,x+t); 80 int k=1; 81 for(int i=1;i<t;i++){ 82 if(x[i]!=x[i-1]){ 83 x[k++]=x[i]; 84 } 85 } 86 //cout<<1<<endl; 87 build(0,k-1,1); 88 //cout<<2<<endl; 89 double ans=0.0; 90 //cout<<t<<endl; 91 for(int i=0;i<t;i++){ 92 int l=lower_bound(x,x+k,edge[i].l)-x; 93 int r=lower_bound(x,x+k,edge[i].r)-x-1; 94 update(l,r,1,edge[i].flag); 95 ans=ans+(edge[i+1].h-edge[i].h)*tree[1].len; 96 //cout<<ans<<endl; 97 } 98 printf("Test case #%d\n",tt); 99 printf("Total explored area: %.2f\n\n",ans); 100 //cout<<ans<<endl; 101 } 102 }
标签:rtu ace starting mono weight break push std single
原文地址:http://www.cnblogs.com/Aa1039510121/p/6506366.html