标签:style blog class code c ext
有如下图半径为R的圆形蛋糕,被切一刀后(图中红色直线),分成两个部分(黄色和绿色),已知其比例为r,求刀痕长度(图中红色直线)。
1000 0.5000 500 0.6183
1928.53 982.49
思路:二分加贪心
#include<iostream> using namespace std; #include<cstdio> #include<cmath> #include<cstdlib> 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; }
标签:style blog class code c ext
原文地址:http://blog.csdn.net/an327104/article/details/26007523