Test instructions: The volume is approximated by the cone area, then the relative error of the approximate value and the true value is calculated.
Calculus plus Math.
Volumetric calculation formula for flat-head vertebral table:
V = 1/3*h* (s1+s2*sqrt (S1*S2)
A faster way to calculate polynomial values, to be proud of ye, the algorithm is for (int i = 0; I >= i--) ans + = ans*x+p[i], one times faster than I wrote this
#include <cstdio>#include<cmath>#include<cstring>Const DoublePI = Atan (1)*4;intpoly[8],q[ -],n;inlineDoubleCALR (Doublex) { DoubleAns = poly[0]; for(inti =1; I <= N; i++) {ans+ = poly[i]*Pow (x,i); } returnans;} InlineDoubleCalint (intx) { DoubleAns =0; for(inti =0, Sz = n<<1; I <= sz; i++) {ans+ = Q[i]*pow (x,i+1)/(i+1); } returnans;} InlineDoubleCalV (intAintb) {memset (Q,0,sizeof(Q)); for(inti =0; I <= N; i++){ for(intj =0; J <= N; J + +) Q[i+J] + = poly[i]*Poly[j]; } return(Calint (b)-calint (a)) *Pi;} InlineDoubleCalS (DoubleRDoubleThetaintslices) { returnR*sin (theta)/2*r*slices;}intMain () {intT; scanf ("%d",&T); intCAS =0; while(t--) {memset (poly,0,sizeof(poly)); scanf ("%d",&N); for(inti = n; I >=0; i--) scanf ("%d", poly+i); intb; scanf ("%d%d",&a,&b); intslices,stacks; scanf ("%d%d",&slices,&stacks); DoubleDX = (b-a) *1.0/stacks, Dtheta =2*pi/slices; DoubleR1 = CALR (a), S1 =CalS (r1,dtheta,slices); Doublex = A +DX; DoubleApe =0; for(inti =0; I < stacks; i++){ DoubleR2 =calr (x); DoubleS2 =CalS (r2,dtheta,slices); DoubleDS = dx/3* (S1+s2+sqrt (s1*S2)); Ape+=DS; X+=DX; R1= R2; S1 =S2; } Doublevol =CalV (A, b); printf ("Case %d:%.4lf\n", ++cas,fabs (Ape-vol)/vol* -); } return 0;}
UVA 12905 Volume of Revolution