题目链接http://ac.jobdu.com/problem.php?pid=1551
转载请注明本文地址 http://blog.csdn.net/yangnanhai93/article/details/41046547
这个题目的主要难度在于分析题目如何解决。
我们得到上图的结果,得S1/S2=r,即S1=r*S2;
又S1+S2=PI*R*R(圆的面积)
得到S1=(PI*R*R)*r/(1+r);
假设刀痕的长度为2L,则其一半为L,且sin(a)=l/R
则a=arcsin(l/R)
扇形面积为S3=R*R*(2*a)/2
三角形的面积为S4=L*sqrt(R*R-L*L)/2
所以S1new=S3-2*S4
此时只需要S1new 和S1的差别不大,即满足精度要求,则L也是满足要求的
注意一点是比例有可能大于1,转换一下,发现其实只需要对变成1/r,就可以变换回来
代码如下:
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define PI asin(1.0)*2
int main()
{
double R,r;
//freopen("data.in","r",stdin);
while(scanf("%lf%lf",&R,&r)!=EOF)
{
if(r>1)
r=1/r;
double low=0,high=R;
double s=PI*R*R*r/(1+r),l,result;
while(true)
{
l=(low+high)/2;
result=R*R*asin(l/R)-sqrt(R*R-l*l)*l;
if(abs(result-s)<0.0000001)
break;
if(result>s)
high=l;
if(result<s)
low=l;
}
printf("%.2lf\n",2*l);
}
return 0;
}
/**************************************************************
Problem: 1551
User: vincent_ynh
Language: C++
Result: Accepted
Time:0 ms
Memory:1100 kb
****************************************************************/