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;}