Adaptive Simpson points
Orz Hzwer
Simpson is a really powerful thing ... A lot of things can be accumulated = =
The positive solution of this problem looks like a ghost animal, at least I do not calculate the geometry of the slag is not written out ... (the intersection of the circle to find the package, ans= convex hull area + a pile of bow area, there are also hollow situation ...) The kind of convex bag how to beg ah Hello! )
1 /**************************************************************2 problem:21783 User:tunix4 language:c++5 result:accepted6 time:8808 Ms7 memory:1372 KB8 ****************************************************************/9 Ten //Bzoj 2178 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; atInlineintGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=1010, inf=~0u>>2; - Const Doubleeps=1e- -; totypedefLong LongLL; +typedefDoubledb; - /******************tamplate*********************/ the intn,top,st,ed; * db Xl[n],xr[n],ans; $ BOOLDel[n];Panax Notoginseng structdata{db X,y,r;} T[n],sk[n]; - structline{db L,r;} P[n]; the db dis (data a,data b) { + returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); A } the BOOLCMP1 (data A,data b) {returna.r<B.R;} + BOOLCMP2 (data A,data b) {returna.x-a.r<b.x-B.R;} - BOOLCmp3 (line A,line b) {returna.l<B.L;} $ voidinit () { $scanf"%d",&n); -F (I,1, N) scanf ("%LF%LF%LF",&t[i].x,&t[i].y,&T[I].R); -Sort (t+1, t+n+1, CMP1); theF (I,1, N) F (j,i+1, N) - if(Dis (t[i],t[j]) <=t[j].r-T[I].R) {Wuyidel[i]=1; Break; the } -F (I,1, N)if(!del[i]) sk[++top]=t[i];n=top; WuSort (sk+1, sk+n+1, CMP2); - } About db GETF (db x) { $ intj,sz=0; DB r,len=0, dis; - F (i,st,ed) { - if(x<=xl[i]| | X>=xr[i])Continue; -Dis=sqrt (sk[i].r-(x-sk[i].x) * (xsk[i].x)); AP[++sz].l=sk[i].y-dis; p[sz].r=sk[i].y+dis; + } theSort (p+1, p+sz+1, Cmp3); -F (I,1, SZ) { $R=P[I].R; the for(j=i+1; j<=sz;j++){ the if(P[j].l>r) Break; the if(R<P[J].R) r=P[J].R; the } -LEN+=R-P[I].L; i=j-1; in } the returnLen; the } About db cal (db l,db fl,db fmid,db fr) { the return(fl+fmid*4+FR) *l/6; the } the DB Simpson (db l,db mid,db r,db fl,db fmid,db fr,db s) { +DB m1= (L+MID)/2, m2= (MID+R)/2; -DB F1=GETF (M1), f2=getf (m2); theDB G1=cal (Mid-l,fl,f1,fmid), g2=cal (R-mid,fmid,f2,fr);Bayi if(Fabs (g1+g2-s) <eps)returng1+G2; the returnSimpson (L,M1,MID,FL,F1,FMID,G1) + the Simpson (MID,M2,R,FMID,F2,FR,G2); - } - voidWork () { the inti,j; the db L,r,mid,fl,fr,fmid; theF (I,1, N) { thexl[i]=sk[i].x-SK[I].R; -xr[i]=sk[i].x+SK[I].R; thesk[i].r*=SK[I].R; the } theF (I,1, N) {94L=xl[i]; R=Xr[i]; the for(j=i+1; j<=n;j++){ the if(Xl[j]>r) Break; the if(Xr[j]>r) r=Xr[j];98 } Aboutst=i; ed=j-1; i=j-1; -Mid= (L+R)/2;101FL=GETF (l); FR=GETF (R); Fmid=GETF (mid);102Ans+=simpson (L,mid,r,fl,fmid,fr,cal (Rl,fl,fmid,fr));103 }104 } the intMain () {106 #ifndef Online_judge107Freopen ("2178.in","R", stdin);108Freopen ("2178.out","W", stdout);109 #endif the init ();111 Work (); theprintf"%.3LF", ans);113 return 0; the}
View Code
"Bzoj" "2178" the area of the circle and