标签:是什么 font [1] style after ios iss arc git
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23181 | Accepted: 8644 |
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<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<algorithm> using namespace std; inline int read(){ int x=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1; for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘; return x*f; } const int MAXN=100001; const int INF=999999; int N,M; double a[100001],b[100001]; int A[100001]; struct data2{ double sum,len; int ct; }tr[1000001]; int tmp,tmp2; struct data{ double x,y1,y2; bool end; }poi[1000001]; int T; bool cmp(data a,data b){ return a.x<b.x; } void build(int l,int r,int rt){ tr[rt].ct=0;tr[rt].sum=0; tr[rt].len=a[r]-a[l]; if(l+1>=r) return ; int mid=(l+r)>>1; build(l,mid,rt*2); build(mid,r,rt*2+1); return ; } void Update(int rt,int l,int r){ if(tr[rt].ct) tr[rt].sum=tr[rt].len; else if(r-l>1) tr[rt].sum=tr[rt*2].sum+tr[rt*2+1].sum; else tr[rt].sum=0; return ; } void add(int l,int r,int rt,int L,int R){ if(L==l&&R==r){ tr[rt].ct++; Update(rt,l,r); return ; } int mid=(l+r)>>1; if(L>=mid) add(mid,r,rt*2+1,L,R); else if(R<=mid) add(l,mid,rt*2,L,R); else{ add(mid,r,rt*2+1,mid,R); add(l,mid,rt*2,L,mid); } Update(rt,l,r); return; } void del(int l,int r,int rt,int L,int R){ if(L==l&&R==r){ tr[rt].ct--; Update(rt,l,r); return ; } int mid=(l+r)>>1; if(L>=mid) del(mid,r,rt*2+1,L,R); else if(R<=mid) del(l,mid,rt*2,L,R); else{ del(mid,r,rt*2+1,mid,R); del(l,mid,rt*2,L,mid); } Update(rt,l,r); return; } double ans; int main(){ while(1){ N=read(); if(!N) break; tmp2=tmp=0;double x1,x2,y1,y2; for(int i=1;i<=N;i++){ cin>>x1>>y1>>x2>>y2; poi[++tmp].x=x1; poi[tmp].y1=y1; poi[tmp].y2=y2; poi[tmp].end=false; poi[++tmp].x=x2; poi[tmp].y1=y1; poi[tmp].y2=y2; poi[tmp].end=true; } for(int i=1;i<=tmp;i+=2){ a[tmp2]=b[tmp2]=poi[i].y1;tmp2++; a[tmp2]=b[tmp2]=poi[i].y2;tmp2++; } sort(poi+1,poi+tmp+1,cmp); sort(a,a+tmp2); int tmp3=0,tmp4=0; tmp3=unique(a,a+tmp2)-a; ans=0; build(0,tmp3-1,1); double lasth; for(int i=1;i<tmp;i++){ if(!poi[i].end) add(0,tmp3-1,1,lower_bound(a,a+tmp3,poi[i].y1)-a,lower_bound(a,a+tmp3,poi[i].y2)-a); else del(0,tmp3-1,1,lower_bound(a,a+tmp3,poi[i].y1)-a,lower_bound(a,a+tmp3,poi[i].y2)-a); ans+=(double)((poi[i+1].x-poi[i].x)*tr[1].sum); } printf("Test case #%d\nTotal explored area: %.2f\n\n",++T,ans); } }
标签:是什么 font [1] style after ios iss arc git
原文地址:http://www.cnblogs.com/wxjor/p/7258163.html