标签:double uniq blog values mission plm iss bool 坐标
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22662 | Accepted: 8478 |
Description
Input
Output
Sample Input
2 10 10 20 20 15 15 25 25.5 0
Sample Output
Test case #1 Total explored area: 180.00
Source
#include<cstdio> #include<algorithm> using namespace std; int n,cnt; int opl,opr,w; double x1[101],x2[101],y1[101],y2[101],hash[201],ans; struct LINE { int xl,xr,f; double h; }line[201]; struct node { int l,r,f; double sum; }tr[201*4]; bool cmp(LINE p,LINE q) { return p.h<q.h; } void build(int k,int l,int r) { tr[k].l=l; tr[k].r=r; if(l==r) return; int mid=l+r>>1; build(k<<1,l,mid); build(k<<1|1,mid+1,r); } void up(int k) { if(tr[k].f) tr[k].sum=hash[tr[k].r+1]-hash[tr[k].l]; else if(tr[k].l==tr[k].r) tr[k].sum=0; else tr[k].sum=tr[k<<1].sum+tr[k<<1|1].sum; } void change(int k) { if(tr[k].l>=opl&&tr[k].r<=opr) { tr[k].f+=w; up(k); return; } int mid=tr[k].l+tr[k].r>>1; if(opl<=mid) change(k<<1); if(opr>mid) change(k<<1|1); up(k); } int main() { int T=0; while(scanf("%d",&n)!=EOF) { if(!n) return 0; T++; cnt=0; ans=0; for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&x1[i],&y1[i],&x2[i],&y2[i]); hash[++cnt]=x1[i]; hash[++cnt]=x2[i]; } sort(hash+1,hash+cnt+1); cnt=unique(hash+1,hash+cnt+1)-(hash+1); for(int i=1;i<=n;i++) { line[i*2-1].xl=lower_bound(hash+1,hash+cnt+1,x1[i])-hash; line[i*2].xl=line[i*2-1].xl; line[i*2-1].xr=lower_bound(hash+1,hash+cnt+1,x2[i])-hash; line[i*2].xr=line[i*2-1].xr; line[i*2-1].h=y1[i]; line[i*2].h=y2[i]; line[i*2-1].f=1; line[i*2].f=-1; } sort(line+1,line+2*n+1,cmp); build(1,1,cnt); for(int i=1;i<=2*n;i++) { opl=line[i].xl; opr=line[i].xr-1; w=line[i].f; change(1); ans+=tr[1].sum*(line[i+1].h-line[i].h); } printf("Test case #%d\nTotal explored area: %.2lf\n\n",T,ans); } }
标签:double uniq blog values mission plm iss bool 坐标
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/6828162.html