UVA 12905 Volume of Revolution

Source: Internet
Author: User
Tags cas

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.