Hdu 2289 Cup (bipartite)

Source: Internet
Author: User

 

Resolve the problem by using the binary method.
This question is disgusting... None of the test examples can be passed at the beginning. If this π is obtained at the beginning, the result is 3.1415926, Which is changed to 99.999026, and the result is 3.1414927 .. I found that this π has a great impact on the results, and this question has a high requirement on the accuracy of π... Then I changed my π to 3.1415926536...
The first condition for determining the exit of the binary is that the result difference is less than 0.000000001. If the result is found to have timed out, The result still times out after it is changed to 0.01... Speechless... Then think about it. The question requires that the result be retained to 6 decimal places, so I changed my judgment to jump out of the cycle.
The condition of the ring is changed to the result after binary and the result difference between the previous result is not greater than 0.000001 ....


AC code:

# Include <iostream> # include <cstdio> # define pai 3.1415926536 using namespace std; int main () {int t; double r, R, h, v, vol, nowh, left, right, nowr, lath; scanf ("% d", & t); while (t --) {scanf ("% lf ", & r, & R, & h, & v); lath = left = 0.0; right = h; while (1) {nowh = (left + right)/2; if (lath <nowh) {if (nowh-lath <0.0000001) // judge whether the difference between the current value and the previous value is less than 0.000001, then exit {break ;}} else {if (Lath-nowh <0.0000001) {break ;}} nowr = nowh * (R-r)/h + r; vol = pai * nowh * (r * r + nowr * nowr)/3; if (vol> v) {right = nowh ;} else {left = nowh;} lath = nowh; // record the last value} printf ("%. 6lf \ n ", nowh);} return 0 ;}

 

Related Article

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.