HUD 2289 Cup with two points

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2289

The main idea is a cup, a round table shape, give you its top circle radius, the radius of the bottom circle, the height of the cup, and at this time the volume of water installed, to seek the height of water.

The problem is to exercise algorithmic thinking, or to form algorithmic thinking.

This is an application of two-point approximation evaluation

The topic has been given the height of the cup is 0~100, so in this range of two points, but went to the question of a decimal point, it is possible to take a higher precision error value

As a condition of two points, two minutes, with this value as the height of water to find out the volume and the actual value of the comparison once, when the error is not greater than the error value, then take as high.

Another round Table volume formula: Set the radius of the bottom is r, the radius of the bottom is R, the height is H v= (1/3) *pi*h* (r^2 + Rr +r^2) pi

1#include <stdio.h>2#include <math.h>3 DoublePi=acos (-1.0);//Pi4 Doublehaha =0.000000001;//take the error value5 6 DoubleYjDoubleRDoubleRDoubleHDoubleH)7 {8     DoubleU = h/h* (r-r) + R;//find out the radius of the water circle9     returnpi/3* (R*r+r*u+u*u) *h;//returns the volume of the Circular water tableTen } One  A DoublelsDoubleRDoubleRDoubleHDoublev) - { -     DoubleLeft,right,temp,mid; theleft =0, right = -; -      while((right-left) >haha)//the binary condition becomes the comparison with the error value -     { -Mid = (left+right)/2; +temp=YJ (r,r,mid,h); -         if(Fabs (TEMP-V) <=haha) +             returnmid; A         Else if(temp<v) atLeft=mid+haha; -         Else -right = mid-haha; -     } -     return(Right+left)/2; - } in  - intMain () to { +     intT; -     Doubler,r,h,v; the      while(~SCANF ("%d",&t)) { *      while(t--) $     {Panax Notoginsengscanf"%LF%LF%LF%LF",&r,&r,&h,&v); -printf"%.6lf\n", LS (r,r,h,v)); the     } +     } A     return 0; the}

HUD 2289 Cup with two points

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.