有如下圖半徑為R的圓形蛋糕,被切一刀後(圖中紅色直線),分成兩個部分(黃色和綠色),已知其比例為r,求刀痕長度(圖中紅色直線)。
1000 0.5000 500 0.6183
1928.53 982.49
思路:二分加貪心
#includeusing 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; }