NYOJ 869 cut cake

Source: Internet
Author: User

Cake cutting time limit: 1000 MS | memory limit: 65535 KB difficulty: 3

Description

A circle cake with a radius of R is divided into two parts (yellow and green) after a knife is cut (the red line in the figure). It is known that the ratio is r, calculate the length of a knife mark (the red line in the figure ).

Input
The input includes multiple groups of test data, including an integer R (1 <= R <= 1000) and a floating point r (0 Output
For each group of test cases, a floating point number is output, which indicates the length of the knife mark and keeps two decimal places.
Sample Input
1000 0.5000500 0.6183
Sample output
1928.53982.49
Idea: Binary and greedy
 #include
      
       using namespace std;#include
       
        #include
        
         #include
         
          const double PI=acos(-1);int main(){double rate,thita,sa,sb,ss,sleft,sright;double low,high,l,r;while(cin>>r>>rate){  ss=r*r*PI;  low = 0.0000001,high = 2*r;  while(low<=high)  {     l=(low+high)/2; thita = asin(l/2/r); sb=r*r/2.0*sin(2*thita); sa = r*r*thita; sleft = sa - sb; sright = ss - sleft; if(sleft>=sright*rate) high = l-0.00001; else low = l+0.00001;  }  printf("%0.2f\n",l);} return 0;}        
         
        
       
      


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.